home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-04-03 | 143.2 KB | 4,991 lines | [TEXT/MPS ] |
- //----------------------------------------------------------------------------------------
- // UView.cp
- // Copyright © 1987-96 by Apple Computer, Inc. All rights reserved.
- //----------------------------------------------------------------------------------------
-
- #ifndef __UVIEW__
- #include "UView.h"
- #endif
-
- // MacApp
-
- #ifndef __UBEHAVIOR__
- #include "UBehavior.h"
- #endif
-
- #ifndef __UCLIPBOARDMGR__
- #include "UClipboardMgr.h"
- #endif
-
- #ifndef __UCOMMAND__
- #include "UCommand.h"
- #endif
-
- #ifndef __UCOREGLOBALS__
- #include "UCoreGlobals.h"
- #endif
-
- #ifndef __UCOREUTILITIES__
- #include "UCoreUtilities.h"
- #endif
-
- #ifndef __UDEBUG__
- #include "UDebug.h"
- #endif
-
- #ifndef __UDEPENDENCIES__
- #include "UDependencies.h"
- #endif
-
- #ifndef __UDISPATCHER__
- #include "UDispatcher.h"
- #endif
-
- #ifndef __UDOCUMENT__
- #include "UDocument.h"
- #endif
-
- #ifndef __UDRAG__
- #include "UDragDrop.h"
- #endif
-
- #ifndef __UDRAWINGENVIRONMENT__
- #include "UDrawingEnvironment.h"
- #endif
-
- #ifndef __UFAILURE__
- #include "UFailure.h"
- #endif
-
- #ifndef __UGEOMETRY__
- #include "UGeometry.h"
- #endif
-
- #ifndef __ULIST__
- #include "UList.h"
- #endif
-
- #ifndef __UMACAPPGLOBALS__
- #include "UMacAppGlobals.h"
- #endif
-
- #ifndef __UMACAPPUTILITIES__
- #include "UMacAppUtilities.h"
- #endif
-
- #ifndef __UMEMORY__
- #include "UMemory.h"
- #endif
-
- #ifndef __UPATCH__
- #include "UPatch.h"
- #endif
-
- #ifndef __UPRINTHANDLER__
- #include "UPrintHandler.h"
- #endif
-
- #ifndef __USCROLLER__
- #include "UScroller.h"
- #endif
-
- #ifndef __USTREAM__
- #include "UStream.h"
- #endif
-
- #ifndef __UVIEWSERVER__
- #include "UViewServer.h"
- #endif
-
- #ifndef __UWINDOW__
- #include "UWindow.h"
- #endif
-
- // Toolbox
-
- #ifndef __DIALOGS__
- #include <Dialogs.h>
- #endif
-
- #ifndef __EDITIONS__
- #include <Editions.h>
- #endif
-
- #ifndef __ERRORS__
- #include <Errors.h>
- #endif
-
- #if qGXViews || qGXPrinting
- # ifndef __GXGRAPHICS__
- # include <GXGraphics.h>
- # endif
- #endif
-
- #ifndef __LOWMEM__
- #include <LowMem.h>
- #endif
-
- #ifndef __RESOURCES__
- #include <Resources.h>
- #endif
-
- #ifndef __SCRAP__
- #include <Scrap.h>
- #endif
-
- #ifndef __TOOLUTILS__
- #include <ToolUtils.h>
- #endif
-
- // ANSI
-
- #ifndef __STDIO__
- #include <stdio.h>
- #endif
-
- //========================================================================================
- // static data members
- //========================================================================================
- TView* TView::gFocusedView;
- Boolean TView::gDrawingPictScrap;
- TView* TView::gDrawingPictScrapView;
- Boolean TView::gPrinting;
-
- #if qGXViews || qGXPrinting
- gxGraphicsClient TView::gGXGraphicsClient;
- #endif
-
- //========================================================================================
- // CLASS CSubViewIterator
- //========================================================================================
- #undef Inherited
- #define Inherited CIterator
-
- //----------------------------------------------------------------------------------------
- // CSubViewIterator::CSubViewIterator:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- CSubViewIterator::CSubViewIterator(const TView* theSuperView,
- Boolean itsForward) :
- fFirstView(theSuperView ? theSuperView->fSubView : NULL),
- fIterateForward(itsForward)
- {
- Reset();
- }
-
- //----------------------------------------------------------------------------------------
- // CSubViewIterator::Reset:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- void CSubViewIterator::Reset()
- {
- fCurrentSubView = fIterateForward ? FirstView() : LastView();
- }
-
- //----------------------------------------------------------------------------------------
- // CSubViewIterator::Advance:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- TView* CSubViewIterator::FirstSubView()
- {
- Reset();
- return fCurrentSubView; // Always return the first View
- }
-
- //----------------------------------------------------------------------------------------
- // CSubViewIterator::Advance:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- TView* CSubViewIterator::NextSubView()
- {
- Advance();
- return fCurrentSubView;
- }
-
- //----------------------------------------------------------------------------------------
- // CSubViewIterator::Advance:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- void CSubViewIterator::Advance()
- {
- if (fCurrentSubView)
- fCurrentSubView = fIterateForward ? NextView(fCurrentSubView) : PreviousView(fCurrentSubView);
- }
-
- //----------------------------------------------------------------------------------------
- // CSubViewIterator::PreviousView:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
- TView* CSubViewIterator::PreviousView(TView* aView) const
- {
- TView * currentView = FirstView();
- while (currentView && (NextView(currentView) != aView))
- currentView = NextView(currentView);
-
- return currentView;
- }
-
-
- //----------------------------------------------------------------------------------------
- // CSubViewIterator::LastView:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
- TView* CSubViewIterator::LastView() const
- {
- TView * currentView = FirstView();
- while (currentView && NextView(currentView))
- currentView = NextView(currentView);
-
- return currentView;
- }
-
- //========================================================================================
- // CLASS TView
- //========================================================================================
- #undef Inherited
- #define Inherited TCommandHandler
-
- #pragma segment MAOpen
- MA_DEFINE_CLASS_M1(TView,
- Inherited);
-
- //----------------------------------------------------------------------------------------
- // TView constructor
- //----------------------------------------------------------------------------------------
- #pragma segment MAOpen
-
- TView::TView() :
- fLocation(gZeroVPt),
- fSize(gZeroVPt),
- fTranslation(gZeroVPt),
- fViewToQDOffset(gZeroVPt),
- fVisibleExtent(gZeroVRect),
- fQDOrigin(gZeroPt),
- fSuperView(NULL),
- fSubView(NULL),
- fNextView(NULL),
- fDocument(NULL),
- fDrawingEnvironment(NULL),
- fAdorners(NULL),
- fUserArea(0),
- fTemplateVersion(kMAThreeOhTemplateVersion),
- fHelpIndex(1),
- fHelpID(kNoResource),
- fCursorID(kNoResource),
- fActiveHL(hlOn),
- fInactiveHL(hlDim),
- fHandlesCursor(TRUE),
- fLetsSubViewsHandleCursor(TRUE),
- fHandlesHelp(TRUE),
- fHandlesFirstClicks(TRUE),
- fLetsSubViewsHandleHelp(TRUE),
- fShown(TRUE),
- fWantsToBeTarget(FALSE),
- fCoordinatesAreInvalid(TRUE)
- #if qDrag
- ,
- fDraggable(FALSE),
- fDroppable(FALSE),
- fDragMoveDeterminer(kNeverMove),
- fDragMoveFamily(kNoIdentifier)
- #endif // qDrag
- {
- fSizeDeterminer[hSel] = sizeVariable;
- fSizeDeterminer[vSel] = sizeVariable;
- }
-
- //----------------------------------------------------------------------------------------
- // TView::IView:
- //----------------------------------------------------------------------------------------
- #pragma segment MAOpen
-
- void TView::IView(TDocument* itsDocument,
- TView* itsSuperView,
- const VPoint& itsLocation,
- const VPoint& itsSize,
- SizeDeterminer itsHSizeDet,
- SizeDeterminer itsVSizeDet)
- {
- ICommandHandler(itsSuperView);
-
- // fSuperView = itsSuperView; set below in AddSubView's call to BeInSuperView.
- fLocation = itsLocation;
- fSize = itsSize;
- fSizeDeterminer[hSel] = itsHSizeDet;
- fSizeDeterminer[vSel] = itsVSizeDet;
-
- FailInfo fi;
- Try(fi)
- {
- if (itsSuperView)
- itsSuperView->AddSubView(this);
- BeInDocument(itsDocument);
- fi.Success();
- }
- else // Recover
- {
- Free();
- fi.ReSignal();
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TView::HandlePostCreate:
- //----------------------------------------------------------------------------------------
- #pragma segment MAOpen
-
- void TView::HandlePostCreate(TDocument* itsDocument)
- {
- if (!fDocument)
- BeInDocument(itsDocument);
- #if qDebugMsg
- else if (fDocument && !IsObject(fDocument))
- ProgramBreak("###Unknown fDocument in TView::HandlePostCreate.");
- #endif
-
- if (HasSubViews())
- {
- CSubViewIterator iter(this);
-
- for (TView * aView = iter.FirstSubView(); iter.More(); aView = iter.NextSubView())
- aView->HandlePostCreate(itsDocument);
- }
-
- TBehavior * aBehavior = GetFirstEnabledBehavior();
- if (aBehavior)
- aBehavior->DoPostCreate(itsDocument);
-
- DoPostCreate(itsDocument);
- }
-
- //----------------------------------------------------------------------------------------
- // TView::DoPostCreate:
- //----------------------------------------------------------------------------------------
- #pragma segment MAOpen
-
- void TView::DoPostCreate(TDocument* /* itsDocument */ )
- {
- #if qDrag
- if (fDroppable && HasDragManager()) // if this view receives drops, register it with its window
- {
- TWindow * itsWindow = GetWindow();
- if (itsWindow)
- itsWindow->RegisterDroppableView(this);
- }
- #endif // qDrag
-
- }
-
- //----------------------------------------------------------------------------------------
- // TView::Clone:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewNonRes
-
- TObject* TView::Clone() // override
- {
- MAVolatileInit(TView * , aClonedView, (TView *)Inherited::Clone());
-
- aClonedView->fSuperView = NULL;
- aClonedView->fSubView = NULL;
- aClonedView->fNextView = NULL;
- aClonedView->fDrawingEnvironment = NULL;
- aClonedView->fAdorners = NULL;
- aClonedView->fNextHandler = NULL;
- aClonedView->fDocument = NULL;
-
- FailInfo fi;
- Try(fi)
- {
- // Extra block needed for correct ordering of failure handlers
- if (HasSubViews())
- {
- CSubViewIterator iter(this);
-
- for (TView * aView = iter.FirstSubView(); iter.More(); aView = iter.NextSubView())
- {
- TView * aClonedSubView = (TView *)aView->Clone();
-
- FailInfo innerfi;
- Try(innerfi)
- {
- aClonedView->AddSubView(aClonedSubView);
- innerfi.Success();
- }
- else
- {
- aClonedSubView->Free();
- innerfi.ReSignal();
- }
- }
- }
-
- if (fDrawingEnvironment)
- aClonedView->fDrawingEnvironment = (TDrawingEnvironment *)fDrawingEnvironment->Clone();
-
- // Extra block needed for correct ordering of failure handlers
- {
- CAdornerIterator iter(this);
-
- for (TAdorner * anAdorner = iter.FirstAdorner(); iter.More(); anAdorner = iter.NextAdorner())
- {
- AdornPriority itsPriority = fAdorners->PriorityAt(iter.CurrentIndex());
-
- if (anAdorner->fFreeOnDeletion) // If its not shared…
- {
- TAdorner * aClonedAdorner = (TAdorner *)anAdorner->Clone();
- aClonedView->AddAdorner(aClonedAdorner, itsPriority, FALSE);
- }
- else
- aClonedView->AddAdorner(anAdorner, itsPriority, FALSE);
- }
- }
- fi.Success();
- }
- else // Recover
- {
- aClonedView->Free();
- fi.ReSignal();
- }
-
- return aClonedView;
- }
-
- //----------------------------------------------------------------------------------------
- // TView::Free:
- //----------------------------------------------------------------------------------------
- #pragma segment MAClose
-
- TView::~TView()
- {
- while (fSubView)
- fSubView->Free();
-
- InvalidateFocus();
- gDispatcher->InvalidateMouseRegions(); // Must re-calc cursor and help rgn.
-
- if (this == gDispatcher->GetTarget()) // Fixup the target chain
- gDispatcher->SetTarget(gDispatcher);
-
- if (fSuperView)
- {
- fSuperView->RemoveSubView(this);
- fSuperView = NULL; // redundant, but safe
- }
-
- fDrawingEnvironment = (TDrawingEnvironment *)FreeIfObject(fDrawingEnvironment);
-
- if (fAdorners)
- {
- CAdornerIterator iter(this);
-
- for (TAdorner * theAdorner = iter.FirstAdorner(); iter.More(); theAdorner = iter.NextAdorner())
- theAdorner->RemovedFromView(this); // theAdorner might get freed here
- }
- fAdorners = (TAdornerList *)FreeIfObject(fAdorners);
-
- if (fDocument)
- {
- fDocument->DeleteView(this);
- fDocument = NULL;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TView::HighlightAdorners:
- //----------------------------------------------------------------------------------------
- #pragma segment MAActivate
-
- void TView::HighlightAdorners(const VRect& area,
- HLState fromHL,
- HLState toHL)
- {
- PenState savePenState;
- HLState localFromHL = fromHL;
- HLState localToHL = toHL;
-
- // The direction of iteration is controlled by the following state transition diagram:
- //
- // toHL
- // || OFF || DIM || ON
- // --------------||-------------||-------------------||-------------------
- // OFF || (NA) || Forward || Forward
- // --------------||-------------||-------------------||-------------------
- // fromHL DIM || Backward || (NA) || Forward
- // --------------||-------------||-------------------||-------------------
- // ON || Backward || Backward || (NA)
- // --------------||-------------||-------------------||-------------------
-
- PenNormal();
- GetPenState(&savePenState);
-
- if (((fromHL == hlOn) && ((toHL == hlDim) || (toHL == hlOff))) || ((fromHL == hlDim) && (toHL == hlOff)))
- {
- CAdornerIterator iter(this, kIterateBackward);
-
- for (TAdorner * anAdorner = iter.FirstAdorner(); iter.More(); anAdorner = iter.NextAdorner())
- {
- if (anAdorner->DoesAdorn(this))
- {
- SetPenState(&savePenState);
- anAdorner->DoHighlightSelection(this, area, localFromHL, localToHL);
- }
- }
- }
- else if ((((fromHL == hlOff) || (fromHL == hlDim)) && (toHL == hlOn)) || ((fromHL == hlOff) && (toHL == hlDim)))
- {
- CAdornerIterator iter(this);
-
- for (TAdorner * anAdorner = iter.FirstAdorner(); iter.More(); anAdorner = iter.NextAdorner())
- {
- if (anAdorner->DoesAdorn(this))
- {
- SetPenState(&savePenState);
- anAdorner->DoHighlightSelection(this, area, localFromHL, localToHL);
- }
- }
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TView::Activate:
- //----------------------------------------------------------------------------------------
- #pragma segment MAActivate
-
- void TView::Activate(Boolean entering)
- {
- if (fAdorners && IsDrawable())
- {
- VRect visRect(GetDrawableRect());
- if (entering)
- HighlightAdorners(visRect, fInactiveHL, fActiveHL);
- else
- HighlightAdorners(visRect, fActiveHL, fInactiveHL);
- }
-
- if (HasSubViews())
- {
- CSubViewIterator iter(this);
-
- for (TView * aView = iter.FirstSubView(); iter.More(); aView = iter.NextSubView())
- aView->Activate(entering);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TView::AddAdorner:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewNonRes
-
- void TView::AddAdorner(TAdorner* anAdorner,
- AdornPriority itsPriority,
- Boolean invalidate)
- {
- Boolean oldObjectPerm = AllocateObjectsFromPerm(FALSE);
- fAdorners = MakeAdornerList();
- fAdorners->AddAdorner(anAdorner, itsPriority);
- AllocateObjectsFromPerm(oldObjectPerm);
-
- anAdorner->AddedToView(this);
-
- if (invalidate)
- anAdorner->InvalidateAdorner(this);
- }
-
- //----------------------------------------------------------------------------------------
- // TView::DeleteAdorner:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewNonRes
-
- void TView::DeleteAdorner(TAdorner* anAdorner,
- Boolean invalidate)
- {
- if (fAdorners)
- {
- CAdornerIterator iter(this);
-
- for (TAdorner * theAdorner = iter.FirstAdorner(); iter.More(); theAdorner = iter.NextAdorner())
- {
- if (theAdorner == anAdorner)
- {
- if (invalidate)
- theAdorner->InvalidateAdorner(this);
- anAdorner->RemovedFromView(this);// anAdorner might get freed here
- fAdorners->DeleteElementsAt(iter.fCurrentIndex, 1);
- }
- }
-
- // dispose of fAdorners if it only contains the default gDrawAdorner
- if ((fAdorners->GetSize() == 1) && (AdornerAt(1) == gDrawAdorner))
- fAdorners = (TAdornerList *)(FreeIfObject(fAdorners));
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TView::DeleteAdornerByID:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewNonRes
-
- void TView::DeleteAdornerByID(IDType itsID,
- Boolean invalidate)
- {
- if (fAdorners)
- {
- CAdornerIterator iter(this);
-
- for (TAdorner * theAdorner = iter.FirstAdorner(); iter.More(); theAdorner = iter.NextAdorner())
- {
- if (theAdorner->fIdentifier == itsID)
- {
- if (invalidate)
- theAdorner->InvalidateAdorner(this);
- theAdorner->RemovedFromView(this);// anAdorner might get freed here
- fAdorners->DeleteElementsAt(iter.fCurrentIndex, 1);
- }
- }
-
- // dispose of fAdorners if it only contains the default gDrawAdorner
- if ((fAdorners->GetSize() == 1) && (AdornerAt(1) == gDrawAdorner))
- fAdorners = (TAdornerList *)(FreeIfObject(fAdorners));
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TView::AdornerAt:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- TAdorner* TView::AdornerAt(ArrayIndex i) const
- {
- return fAdorners ? fAdorners->AdornerAt(i) : NULL;
- }
-
- //----------------------------------------------------------------------------------------
- // TView::AdornerWithID:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- TAdorner* TView::AdornerWithID(IDType itsID) const
- {
- TAdorner* returnVal = NULL;
-
- if (fAdorners)
- {
- CAdornerIterator iter(this);
-
- for (TAdorner * theAdorner = iter.FirstAdorner(); iter.More(); theAdorner = iter.NextAdorner())
- if (theAdorner->fIdentifier == itsID)
- {
- returnVal = theAdorner;
- break;
- }
- }
-
- return returnVal;
- }
-
- //----------------------------------------------------------------------------------------
- // TView::Dim:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- void TView::Dim()
- {
- #if qDebug
- AssumeFocused();
- #endif
-
- PenPat(&qd.gray);
- PenMode(patBic);
- PaintRect(&GetQDExtent());
- }
-
- //----------------------------------------------------------------------------------------
- // TView::GetAdornExtent:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- void TView::GetAdornExtent(VRect& itsAdornExtent)
- {
- itsAdornExtent = GetExtent();
- }
-
- //----------------------------------------------------------------------------------------
- // TView::GetEventNumber:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- EventNumber TView::GetEventNumber()
- {
- return cNoEvent;
- }
-
- //----------------------------------------------------------------------------------------
- // TView::Hilite:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- void TView::Hilite()
- {
- #if qDebug
- AssumeFocused();
- #endif
-
- InvertRect(&GetQDExtent());
- }
-
- //----------------------------------------------------------------------------------------
- // TView::MakeAdornerList:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewNonRes
-
- TAdornerList* TView::MakeAdornerList()
- {
- if (fAdorners)
- return fAdorners;
- else
- {
- MAVolatileInit(TAdornerList * , anAdornerList, new TAdornerList);
- anAdornerList->IAdornerList();
-
- FailInfo fi;
- Try(fi)
- {
- anAdornerList->AddAdorner(gDrawAdorner, kDrawView);// default "Draw" adorner
- fi.Success();
- }
- else // Recover
- {
- anAdornerList->Free();
- fi.ReSignal();
- }
-
- return anAdornerList;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TView::InsertSubView:
- //----------------------------------------------------------------------------------------
- #pragma segment MAOpen
-
- void TView::InsertSubView(TView* theSubView,
- Boolean last)
- {
- #if qDebug
- FailNonObject(theSubView);
- #endif
-
- if (last && fSubView)
- {
- // place at the tail of the list
- register TView* lastView = fSubView;
- register TView* nextView = lastView->fNextView;
- while (nextView)
- {
- lastView = nextView;
- nextView = lastView->fNextView;
- }
- lastView->fNextView = theSubView;
- theSubView->fNextView = NULL;
- }
- else // first
- {
- theSubView->fNextView = fSubView;
- fSubView = theSubView;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TView::DeleteSubView:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewNonRes
-
- void TView::DeleteSubView(TView* theSubView)
- {
- #if qDebug
- FailNonObject(theSubView);
- #endif
-
- if (fSubView)
- {
- if (fSubView == theSubView)
- fSubView = theSubView->fNextView;
- else
- {
- register TView* lastView = fSubView;
- register TView* nextView = fSubView->fNextView;
- while (nextView && (nextView != theSubView))
- {
- lastView = nextView;
- nextView = lastView->fNextView;
- }
-
- if (nextView)
- lastView->fNextView = theSubView->fNextView;
- else
- {
- #if qDebug
- ProgramBreak("Delete subview not in list!");
- #endif
-
- }
- }
-
- theSubView->fNextView = NULL;
- }
-
- }
-
- //----------------------------------------------------------------------------------------
- // TView::AddedASubView:
- //----------------------------------------------------------------------------------------
- #pragma segment MAOpen
-
- void TView::AddedASubView(TView* newSubView)
- {
- if (fSuperView)
- fSuperView->AddedASubView(newSubView);
- }
-
- //----------------------------------------------------------------------------------------
- // TView::AddSubView:
- //----------------------------------------------------------------------------------------
- #pragma segment MAOpen
-
- void TView::AddSubView(TView* theSubView)
- {
- if (theSubView)
- {
- InsertSubView(theSubView);
-
- theSubView->BeInSuperView(this);
- AddedASubView(theSubView);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TView::AdjustFrame:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- void TView::AdjustFrame()
- {
- VRect oldFrame(GetFrame());
- VRect newFrame(oldFrame);
- ComputeFrame(newFrame);
-
- if (newFrame != oldFrame)
- {
- SetFrame(newFrame, kInvalidate);
- DoPagination();
- }
- else if (HasSubViews())
- {
- CSubViewIterator iter(this);
-
- for (TView * aView = iter.FirstSubView(); iter.More(); aView = iter.NextSubView())
- aView->AdjustFrame();
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TView::AssumeFocused:
- //----------------------------------------------------------------------------------------
- #if qDebug
- #pragma segment MADebug
-
- void TView::AssumeFocused() const
- {
- if (gAssumeFocused)
- if (!IsFocused())
- {
- #if qDebugMsg
- fprintf(stderr, ", ClassName=%s\n", GetClassName());
- if (gFocusedView)
- {
- fprintf(stderr, "View actually focused is:\n");
- fprintf(stderr, ", ClassName=%s\n", gFocusedView->GetClassName());
- }
- #endif
- ProgramBreak("Failed AssumeFocused");
- }
- }
- #endif
-
- //----------------------------------------------------------------------------------------
- // TView::AttachPrintHandler:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewNonRes
-
- void TView::AttachPrintHandler(TPrintHandler* itsPrintHandler)
- {
- AddAdorner(gPrintAdorner, kAdornLast, FALSE);// adorner calls DoDrawPrintFeedback
- AddBehavior(itsPrintHandler);
- DoCheckPrinter();
- }
-
- //----------------------------------------------------------------------------------------
- // TView::DetachPrintHandler:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewNonRes
-
- void TView::DetachPrintHandler(TPrintHandler* itsPrintHandler)
- {
- DeleteAdorner(gPrintAdorner, FALSE);
- RemoveBehavior(itsPrintHandler);
- DoCheckPrinter();
- }
-
- //----------------------------------------------------------------------------------------
- // TView::GetPrintHandler:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- TPrintHandler* TView::GetPrintHandler()
- {
- return (TPrintHandler *)GetBehaviorWithIdentifier(kPrintBehaviorID);
- }
-
- //----------------------------------------------------------------------------------------
- // TView::BeInPort:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewNonRes
-
- void TView::BeInPort(GrafPtr itsPort)
- {
- if (itsPort && GetPrintHandler())
- DoCheckPrinter();
-
- if (HasSubViews())
- {
- CSubViewIterator iter(this);
-
- for (TView * aView = iter.FirstSubView(); iter.More(); aView = iter.NextSubView())
- aView->BeInPort(itsPort);
- }
-
- InvalidateCoordinates();
- }
-
- //----------------------------------------------------------------------------------------
- // TView::BeInDocument:
- //----------------------------------------------------------------------------------------
- #pragma segment MAOpen
-
- void TView::BeInDocument(TDocument* itsDocument)
- {
- if (itsDocument && (itsDocument != fDocument))
- {
- fDocument = itsDocument;
- fDocument->AddView(this);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TView::BeInScroller:
- //----------------------------------------------------------------------------------------
- #pragma segment MAOpen
-
- void TView::BeInScroller(TScroller* itsScroller)
- {
- // convert the size to superview location.
-
- if (itsScroller)
- itsScroller->SetScrollLimits(fSize + fLocation, kDontRedraw);
- }
-
- //----------------------------------------------------------------------------------------
- // TView::BeInSuperView:
- //----------------------------------------------------------------------------------------
- #pragma segment MAOpen
-
- void TView::BeInSuperView(TView* itsSuperview)
- {
- if (fSuperView != itsSuperview)
- {
- TView * oldSuperView = fSuperView;
-
- fSuperView = itsSuperview;
- InvalidateFocus(); // the subview may have been focused
-
- if (itsSuperview)
- {
- if (!fNextHandler) // If necessary,
- fNextHandler = itsSuperview; // …hook this view up to an event hander chain.
- BeInPort(GetGrafPort());
- }
- else
- {
- // Removing this view from its superview
- if (fNextHandler == oldSuperView) // If next event handler is the former superview
- fNextHandler = NULL; // take this view out of the event handler chain.
- BeInPort(NULL);
- }
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TView::FindTarget:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- TView* TView::FindTarget()
- {
- TView * foundView = NULL;
-
- if (WantsToBeTarget())
- foundView = this;
- else if (HasSubViews())
- {
- CSubViewIterator iter(this);
-
- for (TView * aView = iter.FirstSubView(); iter.More(); aView = iter.NextSubView())
- {
- foundView = aView->FindTarget();
- if (foundView)
- break;
- }
- }
-
- return foundView;
- }
-
- //----------------------------------------------------------------------------------------
- // TView::SetTargetSelection:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- void TView::SetTargetSelection(Boolean redraw)
- {
- ScrollSelectionIntoView(redraw);
- }
-
- //----------------------------------------------------------------------------------------
- // TView::WantsToBeTarget:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- Boolean TView::WantsToBeTarget() // Override
-
- {
- return fWantsToBeTarget;
- }
-
- //----------------------------------------------------------------------------------------
- // TView::ContainsSubView:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- Boolean TView::ContainsSubView(TView* aSubView) const
- {
- Boolean foundView = FALSE;
-
- if (HasSubViews())
- {
- for (TView * viewToTest = aSubView; viewToTest; viewToTest = viewToTest->fSuperView)
- {
- if (viewToTest->fSuperView == this)
- {
- foundView = TRUE;
- break;
- }
- }
- }
-
- return foundView;
- }
-
-
- //----------------------------------------------------------------------------------------
- // TView::CalcMinFrame:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- VRect TView::CalcMinFrame()
- {
- return GetFrame();
- }
-
- //----------------------------------------------------------------------------------------
- // TView::ClipFurtherTo:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- void TView::ClipFurtherTo(RgnHandle rRgn,
- CPoint deltaOrg)
- {
- #if qDebug
- AssumeFocused();
- #endif
-
- SectRgn(GetClipRegion(qd.thePort), rRgn, rRgn);
- if (deltaOrg != gZeroPt)
- OffsetRgn(rRgn, deltaOrg.h, deltaOrg.v);
- SetClip(rRgn);
- }
-
- //----------------------------------------------------------------------------------------
- // TView::OffsetAndClipFurtherTo:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- void TView::OffsetAndClipFurtherTo(RgnHandle rRgn,
- CPoint deltaOrg)
- {
- #if qDebug
- AssumeFocused();
- #endif
-
- // First offset the clip Rgn
- if (deltaOrg != gZeroPt)
- OffsetRgn(GetClipRegion(qd.thePort), deltaOrg.h, deltaOrg.v);
-
- SectRgn(GetClipRegion(qd.thePort), rRgn, rRgn);
- SetClip(rRgn);
- }
-
- //----------------------------------------------------------------------------------------
- // TView::Close:
- //----------------------------------------------------------------------------------------
- #pragma segment MAClose
-
- void TView::Close()
- {
- Changed(mClosed, this);
-
- if (HasSubViews())
- {
- CSubViewIterator iter(this);
-
- for (TView * aView = iter.FirstSubView(); iter.More(); aView = iter.NextSubView())
- aView->Close();
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TView::ComputeFrame:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- void TView::ComputeFrame(VRect& newFrame)
- {
- VRect minFrame; // will be calculated only when necessary
- Boolean haveMinFrame = FALSE;
-
- // Adjust view size based on size determiners.
- for (VHSelect vhs = vSel; vhs <= hSel; ++vhs)
- {
- VCoordinate dimension;
-
- switch (fSizeDeterminer[vhs])
- {
- case sizeFixed:
- dimension = fSize[vhs];
- break;
-
- case sizeRelSuperView:
- dimension = newFrame.GetSize()[vhs];// newFrame set in
- // SuperViewChangedSize
- break;
-
- case sizeSuperView:
- if (fSuperView)
- dimension = fSuperView->fSize[vhs];
- else
- {
- if (!haveMinFrame)
- {
- minFrame = CalcMinFrame();
- haveMinFrame = TRUE;
- }
- dimension = minFrame.GetSize()[vhs];// Set dimension to a default
- }
- break;
-
- case sizePage:
- {
- // If there is no printhandler we can defer until one is attached
- TPrintHandler * itsPrintHandler = GetPrintHandler();
- if (itsPrintHandler)
- dimension = itsPrintHandler->GetViewPerPage()[vhs];
- else
- {
- if (!haveMinFrame)
- {
- minFrame = CalcMinFrame();
- haveMinFrame = TRUE;
- }
- dimension = minFrame.GetSize()[vhs];// Set dimension to a default
- }
- }
- break;
-
- case sizeFillPages:
- {
- if (!haveMinFrame)
- {
- minFrame = CalcMinFrame();
- haveMinFrame = TRUE;
- }
- // If there is no printhandler we can defer until one is attached
- TPrintHandler * itsPrintHandler = GetPrintHandler();
- if (itsPrintHandler)
- dimension = RoundUp(minFrame.GetSize()[vhs], (short)(itsPrintHandler->GetViewPerPage()[vhs]));
- else
- dimension = minFrame.GetSize()[vhs];// Set dimension to a default
- }
- break;
-
- case sizeVariable: // For sizeVariable dimension is already set correctly
- default:
- if (!haveMinFrame)
- {
- minFrame = CalcMinFrame();
- haveMinFrame = TRUE;
- }
- dimension = minFrame.GetSize()[vhs];// Set dimension to a default
- break;
- }
- newFrame[botRight][vhs] = newFrame[topLeft][vhs] + dimension;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TView::ContainsClipType:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- Boolean TView::ContainsClipType(ResType aType)
- {
- long offset;
-
- return (GetScrap(NULL, aType, &offset) > 0);
- }
-
- //----------------------------------------------------------------------------------------
- // TView::ContainsMouse:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- Boolean TView::ContainsMouse(const VPoint& theMouse)
- {
- CTemporaryRegion extentRgn;
- GetExtentRegion(extentRgn);
-
- return (IsShown() && PtInRgn(ViewToQDPt(theMouse), extentRgn));
- }
-
- //----------------------------------------------------------------------------------------
- // TView::CountSubViews:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- short TView::CountSubViews() const
- {
- short count = 0;
-
- register TView* subView = fSubView;
- while (subView)
- {
- ++count;
- subView = subView->fNextView;
- }
-
- return count;
- }
-
- //----------------------------------------------------------------------------------------
- // TView::DoBreakFollowing:
- //----------------------------------------------------------------------------------------
- #pragma segment MAPrint
-
- VCoordinate TView::DoBreakFollowing(VHSelect vhs,
- VCoordinate previousBreak,
- Boolean& automatic)
- {
- VCoordinate returnVal = 0;
-
- TPrintHandler * itsPrintHandler = GetPrintHandler();
- if (itsPrintHandler)
- returnVal = itsPrintHandler->BreakFollowing(vhs, previousBreak, automatic);
-
- return returnVal;
- }
-
- //----------------------------------------------------------------------------------------
- // TView::DoCalcPageStrips:
- //----------------------------------------------------------------------------------------
- #pragma segment MAPrint
-
- VPoint TView::DoCalcPageStrips()
- {
- TPrintHandler * itsPrintHandler = GetPrintHandler();
-
- return itsPrintHandler ? itsPrintHandler->CalcPageStrips() : gZeroVPt;
- }
-
- //----------------------------------------------------------------------------------------
- // TView::DoCalcViewPerPage:
- //----------------------------------------------------------------------------------------
- #pragma segment MAPrint
-
- VPoint TView::DoCalcViewPerPage()
- {
- TPrintHandler * itsPrintHandler = GetPrintHandler();
-
- return itsPrintHandler ? itsPrintHandler->CalcViewPerPage() : fSize;
- }
-
- //----------------------------------------------------------------------------------------
- // TView::DoCheckPrinter:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewNonRes
-
- void TView::DoCheckPrinter()
- {
- // If you are sizeVariable and are going to want to depend on the printed page geometry
- // then you will want to override this method and add an appropriate test
-
- TPrintHandler * itsPrintHandler = GetPrintHandler();
- if (itsPrintHandler)
- {
- if (itsPrintHandler->fShowBreaks || fSizeDeterminer[vSel] == sizePage || fSizeDeterminer[vSel] == sizeFillPages || fSizeDeterminer[hSel] == sizePage || fSizeDeterminer[hSel] == sizeFillPages)
- itsPrintHandler->Update();
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TView::DoDrawPrintFeedback:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- void TView::DoDrawPrintFeedback(const VRect& area)
- {
- #if qDebug
- AssumeFocused();
- #endif
-
- TPrintHandler * itsPrintHandler = GetPrintHandler();
- if (itsPrintHandler)
- itsPrintHandler->DrawPrintFeedback(area);
- }
-
- //----------------------------------------------------------------------------------------
- // TView::DoDrawPageBreak:
- //----------------------------------------------------------------------------------------
- #pragma segment MAPrint
-
- void TView::DoDrawPageBreak(VHSelect vhs,
- short whichBreak,
- VCoordinate loc,
- Boolean automatic)
- {
- TPrintHandler * itsPrintHandler = GetPrintHandler();
- if (itsPrintHandler)
- itsPrintHandler->DrawPageBreak(vhs, whichBreak, loc, automatic);
- }
-
- //----------------------------------------------------------------------------------------
- // TView::HandlesCursor:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- Boolean TView::HandlesCursor()
- {
- Boolean result = (fHandlesCursor && IsEnabled()) || LetsSubViewsHandleCursor()
- #if qDrag
- ||fDraggable
- #endif
- ;
-
- return result;
- }
-
- //----------------------------------------------------------------------------------------
- // TView::LetsSubViewsHandleCursor:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- Boolean TView::LetsSubViewsHandleCursor()
- {
- return fLetsSubViewsHandleCursor && HasSubViews();
- }
-
- //----------------------------------------------------------------------------------------
- // TView::HandlesHelp:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- Boolean TView::HandlesHelp()
- {
- return fHandlesHelp || LetsSubViewsHandleHelp();
- }
-
- //----------------------------------------------------------------------------------------
- // TView::LetsSubViewsHandleHelp:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- Boolean TView::LetsSubViewsHandleHelp()
- {
- return fLetsSubViewsHandleHelp && HasSubViews();
- }
-
- //----------------------------------------------------------------------------------------
- // TView::UpdateSelection:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- void TView::UpdateSelection(const VPoint& /* theMouse */ ,
- TToolboxEvent* /* event */ )
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TView::DoHighlightSelection:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- void TView::DoHighlightSelection(HLState /* fromHL */,
- HLState /* toHL */)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TView::GetCurrentHL:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- HLState TView::GetCurrentHL()
- {
- return IsActive() ? fActiveHL : fInactiveHL;
- }
-
- //----------------------------------------------------------------------------------------
- // TView::DoMouseCommand:
- //----------------------------------------------------------------------------------------
- #pragma segment MASelCommand
-
- void TView::DoMouseCommand(VPoint& /* theMouse */ ,
- TToolboxEvent* /* event */ ,
- CPoint /* hysteresis */)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TView::DoMouseUp:
- //----------------------------------------------------------------------------------------
- #pragma segment MASelCommand
-
- void TView::DoMouseUp(VPoint& /* theMouse */ ,
- TToolboxEvent* /* event */ ,
- CPoint /* hysteresis */)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TView::DoPagination:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewNonRes
-
- void TView::DoPagination()
- {
- TPrintHandler * itsPrintHandler = GetPrintHandler();
- if (itsPrintHandler)
- itsPrintHandler->RedoPageBreaks();
- }
-
- //----------------------------------------------------------------------------------------
- // TView::DoPrinterChanged:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewNonRes
-
- void TView::DoPrinterChanged()
- {
- TPrintHandler * itsPrintHandler = GetPrintHandler();
- if (itsPrintHandler)
- itsPrintHandler->PrinterChanged();
- }
-
- //----------------------------------------------------------------------------------------
- // TView::DoSetPageOffset:
- //----------------------------------------------------------------------------------------
- #pragma segment MAPrint
-
- void TView::DoSetPageOffset(const VPoint& coord)
- {
- TPrintHandler * itsPrintHandler = GetPrintHandler();
- if (itsPrintHandler)
- itsPrintHandler->SetPageOffset(coord);
- }
-
- //----------------------------------------------------------------------------------------
- // TView::DoSetCursor:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- void TView::DoSetCursor(const VPoint& localPoint,
- RgnHandle cursorRegion)
- {
- #if qDebug
- AssumeFocused();
- #endif
-
- #if qDrag
- RgnHandle dragCursorRegion = NULL;
- if (HasDragManager())
- {
- if (!DoSetDragCursor(localPoint, cursorRegion, dragCursorRegion))
- #endif
-
- {
- ResNumber theCursorID = GetCursorID();
- if (theCursorID != kNoResource)
- {
- CPoint localQDPoint(ViewToQDPt(localPoint));
- if (PtInRgn(localQDPoint, cursorRegion))
- {
- CursHandle aCursor = GetCursor(theCursorID);
- FailNILResource((Handle)aCursor);
- SetCursor(*aCursor);
- }
- else
- SetCursor(&(qd.arrow));
- }
- else
- SetCursor(&(qd.arrow));
-
- #if qDrag
- // remove the drag region from the cursor region so the cursor
- // will be updated if it moves into or out of the drag region
- if (dragCursorRegion)
- DiffRgn(cursorRegion, dragCursorRegion, cursorRegion);
- #endif
-
- }
- #if qDrag
- }
- DisposeIfRgnHandle(dragCursorRegion);
- #endif
-
- // If you claim the cursor don't forget to _PROPERLY_ calculate the cursorRegion or
- // WaitNextEvent might give you a lovely mouse-moved event shower. (Lather up!)
-
- // P.S. In debug this is checked for in our original caller: TApplication.TrackMouse.
- }
-
- //----------------------------------------------------------------------------------------
- // TView::DoShowBalloon:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- void TView::DoShowBalloon(const VPoint& /* localPoint */ ,
- RgnHandle helpRegion,
- const HMMessageRecord& helpMessage,
- CPoint localQDTip,
- const CRect& /* localQDRect */ ,
- short balloonVariant)
- {
- LocalToGlobal(&localQDTip);
-
- OSErr err = (HMShowBalloon(&helpMessage, localQDTip, NULL, NULL, 0, balloonVariant, kHMRegularWindow));
- if (err != hmBalloonAborted)
- FailOSErr(err);
-
- // Intersect with visible region. Excludes the balloon region.
- SectRgn(TWindow::GetVisRegion(qd.thePort), helpRegion, helpRegion);
- SectRgn(GetClipRegion(qd.thePort), helpRegion, helpRegion);
- }
-
- //----------------------------------------------------------------------------------------
- // TView::DoShowHelp:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- void TView::DoShowHelp(const VPoint& localPoint,
- RgnHandle helpRegion)
- {
- if (GetHelpID() != kNoResource)
- {
- GetDefaultHelpRegion(localPoint, helpRegion);
-
- FailInfo fi;
- Try(fi)
- {
- HMMessageRecord helpMessage;
- CPoint tip;
- CRect hotRect;
- short balloonVariant;
-
- GetHelpParameters(localPoint, helpRegion, helpMessage, tip, hotRect, balloonVariant);
- DoShowBalloon(localPoint, helpRegion, helpMessage, tip, hotRect, balloonVariant);
- fi.Success();
- }
- else // Recover
- {
- if (fi.error != hmSkippedBalloon)
- fi.ReSignal();
-
- // fall through
- }
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TView::GetDefaultCursorRegion:
- //----------------------------------------------------------------------------------------
- void TView::GetDefaultCursorRegion(const VPoint&/* localPoint */ ,
- RgnHandle cursorRegion)
- {
- // If we get all the way to this view without any other view having claimed the cursor
- // its because no superview handled it in a "HandleCursor" and no subview handled it
- // in a "DoSetCursor" thus there is a _very_ high probability that this view should
- // set the cursor. Just in case though, we remove the frames.
- //
- // If a containing view wishes to set the cursor for itself && all its subview, the
- // place to do that is in our caller: HandleCursor. See HandleCursor in the homebrew
- // controls TDialogView subclass in DemoDialogs.
- //
- // This strategy lets MacApp provide the _largest_ possible cursor rgn, as a default.
- // This way windows, controls, background views, etc can have nice big cursor rgns but
- // the developer can wrest control if they care to.
-
- static const short kRgnHandleTooBig = 16 * 1024;// regions > 16K don't work too well
-
- #if qDebug
- AssumeFocused();
- #endif
-
- GetExtentRegion(cursorRegion);
-
- // We won't claim subviews' territory
- if (LetsSubViewsHandleCursor())
- {
- Boolean rgnHandleWasTooBig = FALSE;
- CTemporaryRegion subViewFrameRgn;
- CSubViewIterator iter(this);
-
- for (TView * theSubView = iter.FirstSubView(); iter.More(); theSubView = iter.NextSubView())
- {
- if (theSubView->HandlesCursor() && !rgnHandleWasTooBig)
- {
- theSubView->GetExtentRegion(subViewFrameRgn);// Remember, the frame is in OUR
- // coordinate system
- theSubView->LocalToSuperRegion(subViewFrameRgn);
- DiffRgn(cursorRegion, subViewFrameRgn, cursorRegion);// Remove the subview from the claimed rgn
-
- if ((GetHandleSize((Handle)cursorRegion) > kRgnHandleTooBig) || (MemError() != noErr))
- {
- rgnHandleWasTooBig = TRUE;
- SetEmptyRgn(cursorRegion);
- }
- }
- }
- }
- // If you claim the cursor don't forget to _PROPERLY_ calculate the cursorRegion or
- // WaitNextEvent might give you a lovely mouse-moved event shower. (Lather up!)
-
- // P.S. In debug this is checked for in our original caller: TApplication.TrackCursor.
- }
-
- //----------------------------------------------------------------------------------------
- // TView::GetDefaultHelpRegion:
- //----------------------------------------------------------------------------------------
- void TView::GetDefaultHelpRegion(const VPoint& /* localPoint */ ,
- RgnHandle helpRegion)
- {
- static const short kRgnHandleTooBig = 16 * 1024;// regions > 16K don't work too well
-
- #if qDebug
- AssumeFocused();
- #endif
-
- GetExtentRegion(helpRegion);
-
- // We won't claim subviews' territory
- if (LetsSubViewsHandleHelp())
- {
- Boolean rgnHandleWasTooBig = FALSE;
- CTemporaryRegion subViewFrameRgn;
- CSubViewIterator iter(this);
-
- for (TView * theSubView = iter.FirstSubView(); iter.More(); theSubView = iter.NextSubView())
- {
- if (theSubView->HandlesHelp() && !rgnHandleWasTooBig)
- {
- theSubView->GetExtentRegion(subViewFrameRgn);// Remember, the frame is in OUR
- // coordinate system
- theSubView->LocalToSuperRegion(subViewFrameRgn);
- DiffRgn(helpRegion, subViewFrameRgn, helpRegion);// Remove the subview from the claimed rgn
-
- if ((GetHandleSize((Handle)helpRegion) > kRgnHandleTooBig) || (MemError() != noErr))
- {
- rgnHandleWasTooBig = TRUE;
- SetEmptyRgn(helpRegion);
- }
- }
- }
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TView::GetLocalOffsetInSuper:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- VPoint TView::GetLocalOffsetInSuper() const
- {
- return fLocation - fTranslation;
- }
-
- //----------------------------------------------------------------------------------------
- // TView::SetLocalOrigin:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- void TView::SetLocalOrigin(const VPoint& newOrigin,
- Boolean redraw)
- {
- if (fTranslation != -newOrigin)
- {
- fTranslation = -newOrigin;
- InvalidateFocus();
- InvalidateCoordinates();
- if (redraw)
- ForceRedraw();
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TView::GetUserSelection:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- TDesignator* TView::GetUserSelection()
- {
- return fSuperView ? fSuperView->GetUserSelection() : fDocument->GetUserSelection();
- }
-
- //----------------------------------------------------------------------------------------
- // TView::SetUserSelection:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- void TView::SetUserSelection(TDesignator* newSelection)
- {
- if (fSuperView)
- fSuperView->SetUserSelection(newSelection);
- else if (fDocument)
- fDocument->SetUserSelection(newSelection);
- }
-
- //----------------------------------------------------------------------------------------
- // TView::UserSelectionChanged:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- void TView::UserSelectionChanged(TView* changedView)
- {
- if (fSuperView)
- fSuperView->UserSelectionChanged(changedView);
- else if (fDocument)
- fDocument->UserSelectionChanged(changedView);
- }
-
- //----------------------------------------------------------------------------------------
- // TView::ScrollSelectionIntoView:
- //----------------------------------------------------------------------------------------
- #pragma segment MAScroll
-
- void TView::ScrollSelectionIntoView(Boolean redraw)
- {
- // As a default, reveal the view's extent
- RevealRect(GetExtent(), fSize, redraw);
- }
-
- //----------------------------------------------------------------------------------------
- // TView::DoMakeNewDrawingEnvironment:
- //----------------------------------------------------------------------------------------
- #pragma segment MAOpen
-
- TDrawingEnvironment* TView::DoMakeNewDrawingEnvironment()
- {
- TDrawingEnvironment * aDrawingEnvironment = new TDrawingEnvironment;
- aDrawingEnvironment->IDrawingEnvironment();
- return aDrawingEnvironment;
- }
-
- //----------------------------------------------------------------------------------------
- // TView::CreateDrawingEnvironment:
- //----------------------------------------------------------------------------------------
- #pragma segment MAOpen
-
- void TView::CreateDrawingEnvironment()
- {
- if (fDrawingEnvironment == NULL)
- fDrawingEnvironment = DoMakeNewDrawingEnvironment();
- }
-
- //----------------------------------------------------------------------------------------
- // TView::SetDrawingEnvironment:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewNonRes
-
- void TView::SetDrawingEnvironment(TDrawingEnvironment* itsDrawingEnvironment,
- Boolean invalidate)
- {
- // protect against installing same drawing environment
- if (fDrawingEnvironment != itsDrawingEnvironment)
- {
- fDrawingEnvironment = (TDrawingEnvironment *)FreeIfObject(fDrawingEnvironment);
- fDrawingEnvironment = itsDrawingEnvironment;
- }
- if (invalidate)
- ForceRedraw();
- }
-
- //----------------------------------------------------------------------------------------
- // TView::PrepareForDrawing:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- void TView::PrepareForDrawing()
- {
- if (fDrawingEnvironment)
- fDrawingEnvironment->Prepare();
- SetupDrawingEnvironment();
- }
-
- //----------------------------------------------------------------------------------------
- // TView::SetupDrawingEnvironment:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- void TView::SetupDrawingEnvironment()
- {
- if (fDrawingEnvironment)
- fDrawingEnvironment->Setup();
- }
-
- //----------------------------------------------------------------------------------------
- // TView::CompleteDrawing:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- void TView::CompleteDrawing()
- {
- if (fDrawingEnvironment)
- fDrawingEnvironment->Complete();
- }
-
- //----------------------------------------------------------------------------------------
- // TView::Draw:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- void TView::Draw(const VRect& /* area */ )
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TView::DrawContents:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- void TView::DrawContents()
- {
- HandleDraw(GetExtent());
- }
-
- //----------------------------------------------------------------------------------------
- // TView::HandleDraw:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- void TView::HandleDraw(const VRect& area)
- {
- if (!(area & GetVisibleExtent()).Empty() && (IsShown()) && Focus())
- {
- // Even if the visible extent is not empty the Drawable rect might be.
- // The Focus (above) will set the clipping for us so we can use it to determine
- // what can be drawn.
- RgnHandle currentClipRgn = GetClipRegion(qd.thePort);
- CRect clipQDRect((*currentClipRgn)->rgnBBox);
- if (!clipQDRect.Empty()) // can we draw anything at all thru the current clip?
- {
- VRect drawArea(area & QDToViewRect(clipQDRect));
- if (!drawArea.Empty()) // does the requested drawing area intersect the drawable area?
- {
- // As suggested by Ed Anson:
- // Check to see if the drawing area intersects the clipping region
- // before drawing.
- CRect drawQDArea(ViewToQDRect(drawArea));
-
- if (RectInRgn(&drawQDArea, currentClipRgn))// does the requested area intersect the drawable region?
- {
- PrepareForDrawing();
- if (fAdorners)
- DrawAdorners(drawArea);
- else
- Draw(drawArea);
-
- // Give the behavior a chance to draw
- TBehavior * aBehavior = GetFirstEnabledBehavior();
- if (aBehavior)
- aBehavior->Draw(drawArea);
-
- // Draw all of the subviews
- if (HasSubViews())
- {
- CSubViewIterator iter(this);
-
- for (TView * theSubView = iter.FirstSubView(); iter.More(); theSubView = iter.NextSubView())
- {
- VRect subViewDrawArea(drawArea);
- theSubView->SuperToLocalVRect(subViewDrawArea);
-
- VRect subViewDrawAreaExtent(subViewDrawArea & theSubView->GetExtent());
- if (!subViewDrawAreaExtent.Empty())
- theSubView->HandleDraw(subViewDrawAreaExtent);
- }
- }
-
- // add the adornments
- // note that we need to re-focus because we've been left focused on our subviews
- if (!(gPrinting || gDrawingPictScrap) && fAdorners && Focus())
- HighlightAdorners(drawArea, hlOff, GetCurrentHL());
-
- CompleteDrawing();
- }
- }
- }
-
- #if qDebug
- if (gShowInvalidations) // special delay after drawing each view so you can watch it advance
- {
- long finalTicks;
- Delay(15, &finalTicks); // so you can see it
- }
- #endif
-
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TView::DrawAdorners:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- void TView::DrawAdorners(const VRect& area)
- {
- PenState savePenState;
- GetPenState(&savePenState);
-
- CAdornerIterator iter(this);
- for (TAdorner * anAdorner = iter.FirstAdorner(); iter.More(); anAdorner = iter.NextAdorner())
- {
- if (anAdorner->DoesAdorn(this))
- {
- anAdorner->Draw(this, area);
- SetPenState(&savePenState);
- }
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TView::FindSubView:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- TView* TView::FindSubView(IDType itsIdentifier) const
- {
- const TView* returnVal = NULL;
-
- if (fIdentifier == itsIdentifier)
- returnVal = this;
- else if (HasSubViews())
- {
- CSubViewIterator iter(this);
-
- for (TView * theSubView = iter.FirstSubView(); iter.More(); theSubView = iter.NextSubView())
- {
- if (theSubView->fIdentifier == itsIdentifier)
- {
- returnVal = theSubView;
- break;
- }
- else if (theSubView->fSubView)
- {
- TView * foundSubView = theSubView->FindSubView(itsIdentifier);
- if (foundSubView)
- {
- returnVal = foundSubView;
- break;
- }
- }
- }
- }
-
- // break const-ness
- return (TView *)returnVal;
- }
-
- //----------------------------------------------------------------------------------------
- // TView::Focus:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- Boolean TView::Focus()
- {
- Boolean returnVal = FALSE; // Can't focus
-
- if (IsFocused()) // Already focused
- {
- {
- #if qDebug
- GrafPtr currentPort;
-
- GetPort(¤tPort);
- if (GetGrafPort() != currentPort)
- ProgramBreak("TView::Focus: Port is incorrect");
- #endif
- }
-
- returnVal = TRUE;
- }
- else if (gDrawingPictScrapView == this)
- {
- gFocusedView = this;
-
- CRect qdExtent(GetQDExtent());
- CPoint qdOrigin(GetQDOrigin());
- SetOrigin(qdOrigin.h, qdOrigin.v);
- ClipRect(&qdExtent);
- }
- else if (FocusOnSuperView()) // do my own focus
- {
- CPoint qdOrigin(GetQDOrigin());
- SetOrigin(qdOrigin.h, qdOrigin.v); // set the new QD origin
-
- CPoint deltaOrigin;
- if ((TPrintHandler::gCurrPrintHandler != NULL) && (TPrintHandler::gCurrPrintHandler->fView == this))
- deltaOrigin = qdOrigin - TPrintHandler::gCurrPrintHandler->GetQDOrigin();
- else if (fSuperView)
- deltaOrigin = qdOrigin - fSuperView->GetQDOrigin();
- else
- deltaOrigin = gZeroPt;
-
- gFocusedView = this; // Now we have the basic focus
-
- // Add the shaping to the view's extent shape
- CTemporaryRegion rRgn;
- GetExtentRegion(rRgn);
- OffsetAndClipFurtherTo(rRgn, deltaOrigin);
-
- // Add the clipping to the currently visible portion of the extent
- GetVisibleRegion(rRgn);
- ClipFurtherTo(rRgn, gZeroPt);
-
- returnVal = TRUE;
- }
-
- return returnVal;
- }
-
- //----------------------------------------------------------------------------------------
- // TView::FocusOnSuperView:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- Boolean TView::FocusOnSuperView()
- {
- Boolean returnVal = FALSE;
-
- if (TPrintHandler::gCurrPrintHandler && (TPrintHandler::gCurrPrintHandler->fView == this))
- returnVal = TPrintHandler::gCurrPrintHandler->Focus();
- else if (fSuperView)
- returnVal = fSuperView->Focus();
-
- return returnVal;
- }
-
- //----------------------------------------------------------------------------------------
- // TView::ForceRedraw:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- void TView::ForceRedraw()
- {
- if (IsVisible())
- {
- CTemporaryRegion itsExtentRgn;
-
- GetExtentRegion(itsExtentRgn);
- InvalidateRegion(itsExtentRgn);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TView::FreeFromClipboard:
- //----------------------------------------------------------------------------------------
- #pragma segment MAClipboard
-
- void TView::FreeFromClipboard()
- {
- gClipboardMgr->Changed(mFreeClipboardView, this);
-
- if (fDocument)
- fDocument->FreeFromClipboard();
- else
- Free();
- }
-
- //----------------------------------------------------------------------------------------
- // TView::GetStandardSignature:
- //----------------------------------------------------------------------------------------
- #pragma segment MAWriteResource
-
- IDType TView::GetStandardSignature() // override
- {
- return kStdView;
- }
-
- //----------------------------------------------------------------------------------------
- // TView::ReadFrom:
- //----------------------------------------------------------------------------------------
- #pragma segment MAReadResource
-
- void TView::ReadFrom(TStream* aStream)
- {
- Inherited::ReadFrom(aStream); // read in TEventHandler info
-
- // Subclasses of TView should override either TView::ReadFields or TView::ReadSubViews,
- // not TView::ReadFrom.
-
- ReadFields(aStream); // read in fields polymorphically
-
- ReadSubViews(aStream); // read in subviews
- }
-
- //----------------------------------------------------------------------------------------
- // TView::ReadFields:
- //----------------------------------------------------------------------------------------
- #pragma segment MAReadResource
-
- void TView::ReadFields(TStream* aStream)
- {
- FailInfo fi;
- Try(fi)
- {
- fTemplateVersion = aStream->ReadInteger();
-
- VPoint itsLocation;
- aStream->ReadVPoint(itsLocation);
- fLocation = itsLocation;
-
- VPoint itsSize;
- aStream->ReadVPoint(itsSize);
- fSize = itsSize;
-
- Byte itsHSizeDet, itsVSizeDet;
- // formerly SizeDeterminers; however, sizeof(enum) is compiler-dependent
- aStream->ReadBytes(&itsVSizeDet, sizeof(Byte));
- aStream->ReadBytes(&itsHSizeDet, sizeof(Byte));
- fSizeDeterminer[hSel] = (SizeDeterminer)itsHSizeDet;
- fSizeDeterminer[vSel] = (SizeDeterminer)itsVSizeDet;
-
- fShown = aStream->ReadBoolean();
- fWantsToBeTarget = aStream->ReadBoolean();
-
- fHandlesCursor = aStream->ReadBoolean();
- fLetsSubViewsHandleCursor = aStream->ReadBoolean();
- fCursorID = aStream->ReadInteger();
-
- fHandlesHelp = aStream->ReadBoolean();
- fLetsSubViewsHandleHelp = aStream->ReadBoolean();
- fHelpID = aStream->ReadInteger();
- fHelpIndex = aStream->ReadInteger();
-
- TDrawingEnvironment * aDrawingEnvironment = NULL;
- if (aStream->ReadStreamObject((TObject * &)aDrawingEnvironment))
- fDrawingEnvironment = aDrawingEnvironment;
- else
- {
- fDrawingEnvironment = NULL;
- #if qDebugMsg
- ProgramBreak("###Unknown TDrawingEnvironment in TView::ReadFields.");
- #endif
-
- }
-
- TAdornerList * aAdornerList = NULL;
- if (aStream->ReadStreamObject((TObject * &)aAdornerList))
- fAdorners = aAdornerList;
- else
- {
- fAdorners = NULL;
- #if qDebugMsg
- ProgramBreak("###Unknown TAdornerList in TView::ReadFields.");
- #endif
-
- }
-
- fUserArea = aStream->ReadLong();
-
- aStream->ReadIDType(); // read in idtype and ignore it
- fi.Success();
- }
- else // Recover
- {
- Free();
- fi.ReSignal();
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TView::ReadSubViews:
- //----------------------------------------------------------------------------------------
- #pragma segment MAOpen
-
- void TView::ReadSubViews(TStream* aStream)
- {
- FailInfo fi;
- Try(fi)
- {
- short numSubViews = aStream->ReadInteger();// read in count of subviews
-
- for (short count = 0; count < numSubViews; ++count)
- {
- TView * aView = NULL;
-
- if (aStream->ReadStreamObject((TObject * &)aView))
- AddSubView(aView);
- #if qDebugMsg
- else
- ProgramBreak("###Unknown TView in TView::ReadSubViews: Attempting to create a TView.");
- #endif
-
- }
- fi.Success();
- }
- else // Recover
- {
- Free();
- fi.ReSignal();
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TView::WriteTo:
- //----------------------------------------------------------------------------------------
- #pragma segment MAWriteResource
-
- void TView::WriteTo(TStream* aStream)
- {
- Inherited::WriteTo(aStream); // write out TEventHandler info
-
- // Subclasses of TView should override either TView::WriteFields or TView::WriteSubViews,
- // not TView::WriteTo.
-
- if (qWriteTemplateViews)
- {
- WriteFields(aStream); // write out fields polymorphically
-
- WriteSubViews(aStream); // write out subviews
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TView::WriteFields:
- //----------------------------------------------------------------------------------------
- #pragma segment MAWriteResource
-
- void TView::WriteFields(TStream* aStream)
- {
- aStream->WriteInteger(fTemplateVersion);
-
- aStream->WriteVPoint(fLocation);
- aStream->WriteVPoint(fSize);
-
- Byte itsHSizeDet = (Byte)fSizeDeterminer[hSel];
- Byte itsVSizeDet = (Byte)fSizeDeterminer[vSel];
- // formerly SizeDeterminers; however, sizeof(enum) is compiler-dependent
- aStream->WriteBytes(&itsVSizeDet, sizeof(Byte));
- aStream->WriteBytes(&itsHSizeDet, sizeof(Byte));
-
- aStream->WriteBoolean(fShown);
- aStream->WriteBoolean(fWantsToBeTarget);
-
- aStream->WriteBoolean(fHandlesCursor);
- aStream->WriteBoolean(fLetsSubViewsHandleCursor);
- aStream->WriteInteger(fCursorID);
-
- aStream->WriteBoolean(fHandlesHelp);
- aStream->WriteBoolean(fLetsSubViewsHandleHelp);
- aStream->WriteInteger(fHelpID);
- aStream->WriteInteger(fHelpIndex);
-
- aStream->WriteStreamObject(fDrawingEnvironment);
-
- aStream->WriteStreamObject(fAdorners, kStandardObject);
-
- aStream->WriteLong(fUserArea);
-
- aStream->WriteIDType(GetStandardSignature());// write it out again for Rez-ability
- }
-
- //----------------------------------------------------------------------------------------
- // TView::WriteSubViews:
- //----------------------------------------------------------------------------------------
- #pragma segment MAWriteResource
-
- void TView::WriteSubViews(TStream* aStream)
- {
- aStream->WriteInteger(CountSubViews()); // write out count of subviews
-
- if (HasSubViews())
- {
- CSubViewIterator iter(this);
-
- for (TView * theSubView = iter.FirstSubView(); iter.More(); theSubView = iter.NextSubView())
- aStream->WriteStreamObject(theSubView, kStandardObject);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TView::GetContext:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- TCommandHandler* TView::GetContext(CommandNumber/* aCommandNumber */ )// Override
- {
- return fDocument ? fDocument : (TCommandHandler*)GetWindow();
- }
-
- //----------------------------------------------------------------------------------------
- // TView::GetExtent:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- VRect TView::GetExtent() const
- {
- // Allow for the origin of the view's coordinate system.
- return VRect(gZeroVPt, fSize) - (GetLocalOffsetInSuper() - fLocation);
- }
-
- //----------------------------------------------------------------------------------------
- // TView::GetExtentRegion:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- void TView::GetExtentRegion(RgnHandle itsExtentRgn)
- {
- RectRgn(itsExtentRgn, &GetQDExtent());
- }
-
- //----------------------------------------------------------------------------------------
- // TView::GetFrame:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- VRect TView::GetFrame() const
- {
- return VRect(fLocation, fLocation + fSize);
- }
-
- //----------------------------------------------------------------------------------------
- // TView::GetGrafPort:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- GrafPtr TView::GetGrafPort()
- {
- GrafPtr returnVal = NULL;
-
- if (fDrawingEnvironment)
- returnVal = fDrawingEnvironment->GetGrafPort();
- if (!returnVal)
- {
- if (gPrinting || gDrawingPictScrap)
- returnVal = qd.thePort; //thePort assumed to be set by print handler
- else if (fSuperView)
- returnVal = fSuperView->GetGrafPort();
- }
- return returnVal;
- }
-
- //----------------------------------------------------------------------------------------
- // TView::GetPartCode:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewNonRes
-
- short TView::GetPartCode(const VPoint& theMouse)
- {
- return GetExtent().Contains(theMouse) ? inContent : inDesk;
- }
-
- //----------------------------------------------------------------------------------------
- // TView::GetPrintExtent:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewNonRes
-
- VRect TView::GetPrintExtent()
- {
- return GetExtent();
- }
-
- //----------------------------------------------------------------------------------------
- // TView::GetQDExtent:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- CRect TView::GetQDExtent()
- {
- return ViewToQDRect(GetExtent());
- }
-
- //----------------------------------------------------------------------------------------
- // TView::GetScroller:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- TScroller* TView::GetScroller(Boolean immediateSuperView)
- {
- TScroller * returnVal = NULL;
-
- if (fSuperView)
- {
- TScroller * aScroller = fSuperView->GetScroller(immediateSuperView);
- if ((aScroller == fSuperView) || (!immediateSuperView))
- returnVal = aScroller;
- }
- return returnVal;
- }
-
- //----------------------------------------------------------------------------------------
- // TView::GetVisibleRect:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- VRect TView::GetVisibleRect()
- {
- return QDToViewRect(GetVisibleQDRect());
- }
-
- //----------------------------------------------------------------------------------------
- // TView::GetVisibleQDRect:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- CRect TView::GetVisibleQDRect()
- {
- CTemporaryRegion visibleRgn;
-
- GetVisibleRegion(visibleRgn);
-
- return (*(RgnHandle)visibleRgn)->rgnBBox;
- }
-
- //----------------------------------------------------------------------------------------
- // TView::GetVisibleRegion:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- void TView::GetVisibleRegion(RgnHandle visibleRgn)
- {
- VRect visibleExtent(GetVisibleExtent());
-
- if (visibleExtent.Empty())
- SetEmptyRgn(visibleRgn);
- else
- {
- RectRgn(visibleRgn, &ViewToQDRect(visibleExtent));
- VisibleRgn(visibleRgn);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TView::GetDrawableRect:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- VRect TView::GetDrawableRect()
- {
- return QDToViewRect(GetDrawableQDRect());
- }
-
- //----------------------------------------------------------------------------------------
- // TView::GetDrawableQDRect:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- CRect TView::GetDrawableQDRect()
- {
- CTemporaryRegion drawableRgn;
-
- GetDrawableRegion(drawableRgn);
-
- return (*(RgnHandle)drawableRgn)->rgnBBox;
- }
-
- //----------------------------------------------------------------------------------------
- // TView::GetDrawableRegion:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- void TView::GetDrawableRegion(RgnHandle drawRgn)
- {
- GetVisibleRegion(drawRgn);
- if (!EmptyRgn(drawRgn))
- DrawableRgn(drawRgn);
- }
-
- //----------------------------------------------------------------------------------------
- // TView::GetHelpID:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- ResNumber TView::GetHelpID()
- {
- return fHelpID;
- }
-
- //----------------------------------------------------------------------------------------
- // TView::GetHelpIndex:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- short TView::GetHelpIndex()
- {
- return fHelpIndex;
- }
-
- //----------------------------------------------------------------------------------------
- // TView::GetHelpState:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- short TView::GetHelpState()
- {
- return IsEnabled() ? kHMEnabledItem : kHMDisabledItem;
- }
-
- //----------------------------------------------------------------------------------------
- // TView::GetCursorID:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- ResNumber TView::GetCursorID()
- {
- return fCursorID;
- }
-
- //----------------------------------------------------------------------------------------
- // TView::GetHelpParameters:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- void TView::GetHelpParameters(const VPoint& localPoint,
- RgnHandle helpRegion,
- HMMessageRecord& helpMessage,
- CPoint& localQDTip,
- CRect& localQDRect,
- short& balloonVariant)
- {
- gDispatcher->GetHelpParameters(GetHelpID(), GetHelpIndex(),// component number within resource
- GetHelpState(),// view state: enabled, disabled etc.
- helpMessage, localQDTip, localQDRect, balloonVariant);
-
- // Ignore the hotRect from the resource
- if (helpRegion)
- {
- localQDRect = (*helpRegion)->rgnBBox;
- if ((localQDTip.h < 0) || (localQDTip.v < 0))
- {
- //GetMouse(localQDTip); ???
- localQDTip = ViewToQDPt(localPoint);
- }
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TView::GetRootView:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- TView* TView::GetRootView()
- {
- return fSuperView ? fSuperView->GetRootView() : this;
- }
-
- //----------------------------------------------------------------------------------------
- // TView::GetWindow:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- TWindow* TView::GetWindow() const
- {
- return fSuperView ? fSuperView->GetWindow() : NULL;
- }
-
- //----------------------------------------------------------------------------------------
- // TView::GivePasteData:
- //----------------------------------------------------------------------------------------
- #pragma segment MAClipboard
-
- long TView::GivePasteData(Handle aDataHandle,
- ResType dataType)
- {
- // Make sure the scrap handle is grown out of permanent memory. If it
- // was grown out of temporary memory it would eat away at our code space.
- Boolean savedPerm = PermAllocation(TRUE);
-
- long offset;
- long err = GetScrap(aDataHandle, dataType, &offset);
-
- savedPerm = PermAllocation(savedPerm);
-
- #if qDebugMsg
- if (err < 0)
- fprintf(stderr, "TView.GivePasteData got error code # %d from GetScrap for type %s\n", err, (char*) & dataType);
- #endif
-
- return err;
- }
-
- //----------------------------------------------------------------------------------------
- // TView::HandleCursor:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- void TView::HandleCursor(const VPoint& theMouse,
- RgnHandle cursorRegion)
- {
-
- // Assume if we got here then we already know the mouse is in this view
- if (LetsSubViewsHandleCursor())
- {
- CSubViewIterator iter(this, kIterateBackward);
-
- for (TView * theSubView = iter.FirstSubView(); iter.More(); theSubView = iter.NextSubView())
- {
- VPoint subViewPt(theMouse);
-
- theSubView->SuperToLocal(subViewPt);
- if ((theSubView->ContainsMouse(subViewPt) && theSubView->HandlesCursor()))
- {
- theSubView->HandleCursor(subViewPt, cursorRegion);
- // bring the cursor Rgn back to our coordinate system.
- theSubView->LocalToSuperRegion(cursorRegion);
- break;
- }
- }
- }
-
- if (EmptyRgn(cursorRegion) && Focus())
- {
- // First let the Behavior have a crack at handling the cursor
- Boolean proceed = TRUE;
-
- GetDefaultCursorRegion(theMouse, cursorRegion);
-
- if (GetFirstBehavior())
- proceed = !((TBehavior *)GetFirstBehavior())->DoSetCursor(theMouse, cursorRegion);
-
- if (proceed)
- DoSetCursor(theMouse, cursorRegion);
-
- // Restrict the claimed cursor region to the visible extent of this view
- RestrictRegionToVisible(cursorRegion);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TView::HandleHelp:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- void TView::HandleHelp(const VPoint& theMouse,
- RgnHandle helpRegion)
- {
- //Assume if we got here then we already know the mouse is in this view
-
- if (LetsSubViewsHandleHelp())
- {
- CSubViewIterator iter(this, kIterateBackward);
-
- for (TView * theSubView = iter.FirstSubView(); iter.More(); theSubView = iter.NextSubView())
- {
- VPoint subViewPt(theMouse);
-
- theSubView->SuperToLocal(subViewPt);
-
- if (theSubView->ContainsMouse(subViewPt) && theSubView->HandlesHelp())
- {
- theSubView->HandleHelp(subViewPt, helpRegion);
-
- // bring the help Rgn back to our coordinate system.
- theSubView->LocalToSuperRegion(helpRegion);
- break;
- }
- }
- }
-
- if (EmptyRgn(helpRegion) && HandlesHelp() && Focus())
- {
- DoShowHelp(theMouse, helpRegion);
-
- // Restrict the claimed help region to the visible extent of this view
- RestrictRegionToVisible(helpRegion);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TView::HandleMouseDown:
- //----------------------------------------------------------------------------------------
- #pragma segment MASelCommand
-
- Boolean TView::HandleMouseDown(const VPoint& theMouse,
- TToolboxEvent* event,
- CPoint hysteresis,
- EMouseDownType mouseDownType)
- {
- Boolean wasHandled = FALSE;
-
- Boolean isFirstClick = (mouseDownType == kFirstClick_dragOnly || mouseDownType == kFirstClick_dragOrClick);
- Boolean canDoMouse = (mouseDownType == kDragOrClick || mouseDownType == kFirstClick_dragOrClick);
-
- if (HasSubViews())
- {
- CSubViewIterator iter(this, kIterateBackward);
-
- for (TView * theSubView = iter.FirstSubView(); iter.More(); theSubView = iter.NextSubView())
- {
- VPoint subViewPt = theMouse;
-
- theSubView->SuperToLocal(subViewPt);
- if (theSubView->ContainsMouse(subViewPt))
- if (theSubView->HandleMouseDown(subViewPt, event, hysteresis, mouseDownType))
- {
- wasHandled = TRUE;
- break;
- }
- }
- }
-
- if (!wasHandled && Focus()) // see if we can handle it
- {
- VPoint tempMouse = theMouse; // We do this so we can pass a const to DoMouseCommand
- CPoint globalMouse(ViewToQDPt(theMouse));
- LocalToGlobal(&globalMouse);
-
- // This is important to allowing the cursor to change when selecting
- if (gDispatcher->IsCursorRgnInvalid())
- {
- gDispatcher->TrackCursor(globalMouse);
- Focus();
- }
-
- if (canDoMouse)
- UpdateSelection(tempMouse, event);
-
- #if qDrag
- // if the user is dragging, and the view wants to drag, initiate a drag
- if (HasDragManager())
- {
- RgnHandle dragCursorRegion = DoMakeDragCursorRegion();
- if (WillDrag(theMouse, dragCursorRegion))
- {
- dragCursorRegion = DisposeIfRgnHandle(dragCursorRegion);
- short cursorID = GetIsDraggingCursorID();
- if (cursorID != kNoResource)
- {
- CursHandle aCursor = GetCursor(cursorID);
- FailNILResource((Handle)aCursor);
- SetCursor(*aCursor);
- }
- else
- SetCursor(&(qd.arrow));
-
- if (TDragDropSession::fgDragDropSession->UserIsDragging(globalMouse))
- {
- DoGetDragProxy()->HandleDrag(event);
- wasHandled = TRUE;
- }
- }
- else
- dragCursorRegion = DisposeIfRgnHandle(dragCursorRegion);
- }
- #endif // qDrag
-
- if (!wasHandled && isFirstClick)
- {
- TWindow * theWindow = GetWindow();
- if (theWindow != NULL)
- {
- if (!fHandlesFirstClicks)
- wasHandled = TRUE;
- theWindow->Select();
- gDispatcher->UpdateAllWindows();
- Focus();
- }
- }
-
- if (!wasHandled && canDoMouse && IsEnabled())
- {
- if (WantsToBeTarget() && !BecomeTarget())
- wasHandled = TRUE; // don't allow subviews to handle it
- else
- {
- // Give behaviors a chance to handle the mouseDown
- TBehavior * aBehavior = GetFirstEnabledBehavior();
- if (aBehavior)
- wasHandled = aBehavior->DoMouseCommand(tempMouse, event, hysteresis);
-
- if (!wasHandled && IsEnabled())
- {
- DoMouseCommand(tempMouse, event, hysteresis);
- wasHandled = TRUE;
- }
- }
- }
-
- if (wasHandled || GetDraggable())
- gDispatcher->InvalidateMouseRegions();
- }
-
- return wasHandled;
- }
-
- //----------------------------------------------------------------------------------------
- // TView::HandleMouseUp:
- //----------------------------------------------------------------------------------------
- #pragma segment MASelCommand
-
- Boolean TView::HandleMouseUp(const VPoint& theMouse,
- TToolboxEvent* event,
- CPoint hysteresis)
- {
- Boolean wasHandled = FALSE;
-
- if (HasSubViews())
- {
- CSubViewIterator iter(this, kIterateBackward);
-
- for (TView * theSubView = iter.FirstSubView(); iter.More(); theSubView = iter.NextSubView())
- {
- VPoint subViewPt = theMouse;
-
- theSubView->SuperToLocal(subViewPt);
- if (theSubView->ContainsMouse(subViewPt))
- if (theSubView->HandleMouseUp(subViewPt, event, hysteresis))
- {
- wasHandled = TRUE;
- break;
- }
- }
- }
-
- if (!wasHandled && Focus()) // see if we can handle it
- {
- VPoint tempMouse(theMouse); // We do this so we can pass a const to DoMouseCommand
-
- // Change added to support behaviors
- Boolean proceed = TRUE;
-
- TBehavior * aBehavior = GetFirstEnabledBehavior();
- if (aBehavior)
- proceed = !aBehavior->DoMouseUp(tempMouse, event, hysteresis);
-
- if (proceed && IsEnabled())
- {
- DoMouseUp(tempMouse, event, hysteresis);
- wasHandled = TRUE;
- }
- else
- wasHandled = !proceed;
- }
-
- return wasHandled;
- }
-
- //----------------------------------------------------------------------------------------
- // TView::HasPendingUpdate:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- Boolean TView::HasPendingUpdate()
- {
- return fSuperView ? fSuperView->HasPendingUpdate() : FALSE;
- }
-
- //----------------------------------------------------------------------------------------
- // TView::InvalidateVRect:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- void TView::InvalidateVRect(const VRect& badVRect)
- {
- InvalidateRect(ViewToQDRect(badVRect));
- }
-
- //----------------------------------------------------------------------------------------
- // TView::InvalidateRect:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- void TView::InvalidateRect(const CRect& badRect)
- {
- CTemporaryRegion badRectRgn;
-
- RectRgn(badRectRgn, &badRect);
- InvalidateRegion(badRectRgn);
- }
-
- //----------------------------------------------------------------------------------------
- // TView::InvalidateRegion:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- void TView::InvalidateRegion(const RgnHandle badRgn)
- {
- if (Focus())
- {
- CTemporaryRegion visibleBadRgn;
-
- RectRgn(visibleBadRgn, &ViewToQDRect(GetVisibleExtent()));
- SectRgn(badRgn, visibleBadRgn, visibleBadRgn);
- if (!EmptyRgn(visibleBadRgn))
- DoInvalidateRegion(visibleBadRgn);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TView::DoInvalidateRegion:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- void TView::DoInvalidateRegion(const RgnHandle badRgn)
- {
- if (fSuperView)
- fSuperView->DoInvalidateRegion(badRgn); // see if someone knows how
- }
-
- //----------------------------------------------------------------------------------------
- // TView::IsShown:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- Boolean TView::IsShown()
- {
- // Rewritten as single exit code. (It's smaller and faster object code too!)
- Boolean returnVal = fShown;
-
- if (!(gDrawingPictScrap && gDrawingPictScrapView == this) && !((TPrintHandler::gCurrPrintHandler != NULL) && (TPrintHandler::gCurrPrintHandler->fView == this)) && fSuperView)
- returnVal = returnVal && fSuperView->IsShown();// A view can't be shown if its superview isn't shown
-
- return returnVal;
- }
-
- //----------------------------------------------------------------------------------------
- // TView::IsActive:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- Boolean TView::IsActive()
- {
- return fSuperView ? fSuperView->IsActive() : FALSE;// Can't be "active" without a superview
- }
-
- //----------------------------------------------------------------------------------------
- // TView::IsDrawable:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- Boolean TView::IsDrawable()
- {
- // Rewritten as single exit code. (It's smaller and faster object code too!)
- // also avoid call to GetDrawableQDRect by checking the clipRgn directly.
- Boolean returnVal = FALSE;
-
- if (IsShown() && Focus()) // leaves view focused if it is drawable
- returnVal = !EmptyRgn(GetClipRegion(qd.thePort));
-
- return returnVal;
- }
-
- //----------------------------------------------------------------------------------------
- // TView::IsVisible:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- Boolean TView::IsVisible()
- {
- Boolean returnVal = FALSE;
-
- if (IsShown())
- returnVal = IsFocused() ? !GetVisibleQDRect().Empty() : !GetVisibleExtent().Empty();
-
- return returnVal;
- }
-
- //----------------------------------------------------------------------------------------
- // TView::LocalToSuper:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- void TView::LocalToSuper(VPoint& thePoint) const
- {
- thePoint += GetLocalOffsetInSuper();
- }
-
- //----------------------------------------------------------------------------------------
- // TView::LocalToSuperVRect:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- void TView::LocalToSuperVRect(VRect& viewRect) const
- {
- viewRect += GetLocalOffsetInSuper();
- }
-
- //----------------------------------------------------------------------------------------
- // TView::LocalToSuperRegion:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- void TView::LocalToSuperRegion(RgnHandle theRgn)
- {
- VPoint localViewPt(QDToViewPt(gZeroPt)); // get 0 in View Space
- LocalToSuper(localViewPt);
-
- CPoint superQDPt(fSuperView ? fSuperView->ViewToQDPt(localViewPt) : localViewPt.ToPoint());
-
- OffsetRgn(theRgn, (short)superQDPt.h, (short)superQDPt.v);
- }
-
-
- //----------------------------------------------------------------------------------------
- // TView::LocalToWindowRegion:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- void TView::LocalToWindowRegion(RgnHandle theRgn)
- {
- VPoint localViewPt(QDToViewPt(gZeroPt)); // get 0 in view space
- LocalToWindow(localViewPt);
-
- TWindow * itsWindow = GetWindow();
- CPoint windowQDPt(itsWindow ? itsWindow->ViewToQDPt(localViewPt) : localViewPt.ToPoint());
-
- OffsetRgn(theRgn, (short)windowQDPt.h, (short)windowQDPt.v);
- }
-
- //----------------------------------------------------------------------------------------
- // TView::LocalToGlobalRegion:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- void TView::LocalToGlobalRegion(RgnHandle theRgn)
- {
- CPoint globalQDPt(ViewToQDPt(gZeroPt));
- LocalToGlobal(&globalQDPt);
-
- OffsetRgn(theRgn, (short)globalQDPt.h, (short)globalQDPt.v);
- }
-
- //----------------------------------------------------------------------------------------
- // TView::LocalToWindow:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- void TView::LocalToWindow(VPoint& thePoint) const
- {
- if (fSuperView)
- {
- LocalToSuper(thePoint);
- fSuperView->LocalToWindow(thePoint);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TView::InvalidateFrameDifference:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewNonRes
-
- void TView::InvalidateFrameDifference(const VRect& oldFrame,
- const VRect& newFrame)
- {
- if (fSuperView && FocusOnSuperView())
- {
- CRect oldQDFrame(fSuperView->ViewToQDRect(oldFrame));
- CTemporaryRegion oldFrameRgn;
- RectRgn(oldFrameRgn, &oldQDFrame);
-
- CRect newQDFrame(fSuperView->ViewToQDRect(newFrame));
- CTemporaryRegion newFrameRgn;
- RectRgn(newFrameRgn, &newQDFrame);
-
- // If it didn't move then only the size difference is invalid if the view
- // doesn't have contents proportional to its size. Otherwise both the regions
- // are invalid
- if (oldFrame[topLeft] == newFrame[topLeft])
- XorRgn(oldFrameRgn, newFrameRgn, newFrameRgn);
- else
- UnionRgn(oldFrameRgn, newFrameRgn, newFrameRgn);
-
- fSuperView->InvalidateRegion(newFrameRgn);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TView::SetFrame:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewNonRes
-
- void TView::SetFrame(const VRect& newFrame,
- Boolean invalidate)
- {
- VRect oldFrame(GetFrame());
-
- if (newFrame != oldFrame)
- {
- // update the frame stored in the view
- fLocation = newFrame[topLeft];
- fSize = newFrame.GetSize();
-
- InvalidateFocus(); // Must re-focus because frame changed
- InvalidateCoordinates(); // Re-calc all the offsets
-
- gDispatcher->InvalidateMouseRegions(); // Must re-calc cursor and help regions
-
- if (invalidate)
- InvalidateFrameDifference(oldFrame, newFrame);
-
- // • Let my adorners know that my frame changed
- NotifyAdornersOfFrameChange(oldFrame, newFrame, invalidate);
-
- // • Let my superview know that my frame changed
- if (fSuperView)
- fSuperView->SubViewChangedFrame(this, oldFrame, newFrame, invalidate);
-
- // • Let my subviews know that my frame changed
- NotifySubViewsOfFrameChange(oldFrame, newFrame, invalidate);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TView::NotifyAdornersOfFrameChange:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewNonRes
-
- void TView::NotifyAdornersOfFrameChange(const VRect& oldFrame,
- const VRect& newFrame,
- Boolean invalidate)
- {
- if (fAdorners && Focus())
- {
- CAdornerIterator iter(this);
-
- for (TAdorner * anAdorner = iter.FirstAdorner(); iter.More(); anAdorner = iter.NextAdorner())
- anAdorner->ViewChangedFrame(this, oldFrame, newFrame, invalidate);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TView::NotifySubViewsOfFrameChange:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewNonRes
-
- void TView::NotifySubViewsOfFrameChange(const VRect& oldFrame,
- const VRect& newFrame,
- Boolean invalidate)
- {
- if (HasSubViews())
- {
- CSubViewIterator iter(this);
-
- for (TView * theSubView = iter.FirstSubView(); iter.More(); theSubView = iter.NextSubView())
- theSubView->SuperViewChangedFrame(oldFrame, newFrame, invalidate);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TView::Locate:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewNonRes
-
- void TView::Locate(const VPoint& newLoc,
- Boolean invalidate)
- {
- SetFrame(VRect(newLoc, newLoc + fSize), invalidate);
- }
-
- //----------------------------------------------------------------------------------------
- // TView::MakeFirstSubView:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewNonRes
-
- void TView::MakeFirstSubView(TView* theSubView)
- {
- DeleteSubView(theSubView);
- InsertSubView(theSubView, kInsertSubViewFirst);
- }
-
- //----------------------------------------------------------------------------------------
- // TView::MakeLastSubView:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewNonRes
-
- void TView::MakeLastSubView(TView* theSubView)
- {
- DeleteSubView(theSubView);
- InsertSubView(theSubView);
- }
-
- //----------------------------------------------------------------------------------------
- // TView::Open:
- //----------------------------------------------------------------------------------------
- #pragma segment MAOpen
-
- void TView::Open()
- {
- if (HasSubViews())
- {
- CSubViewIterator iter(this);
-
- for (TView * theSubView = iter.FirstSubView(); iter.More(); theSubView = iter.NextSubView())
- theSubView->Open();
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TView::PageInteriorChanged:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewNonRes
-
- void TView::PageInteriorChanged(const VRect& /* newInterior */ )
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TView::RevealUndoRedo:
- //----------------------------------------------------------------------------------------
- #pragma segment MAApplicationRes
-
- void TView::RevealUndoRedo(TCommand* command) // override
- {
- Inherited::RevealUndoRedo(command);
-
- SetTargetSelection(kRedraw);
-
- TWindow * window = GetWindow();
- if (window)
- window->Select();
- }
-
- //----------------------------------------------------------------------------------------
- // TView::QDToViewPt:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- VPoint TView::QDToViewPt(CPoint qdPoint)
- {
- return VPoint(qdPoint) + GetViewToQDOffset();
- }
-
- //----------------------------------------------------------------------------------------
- // TView::QDToViewRect:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- VRect TView::QDToViewRect(const CRect& qdRect)
- {
- return VRect(qdRect) + GetViewToQDOffset();
- }
-
- //----------------------------------------------------------------------------------------
- // TView::RemovedASubView:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewNonRes
-
- void TView::RemovedASubView(TView* theSubView)
- {
- if (fSuperView)
- fSuperView->RemovedASubView(theSubView);
- }
-
- //----------------------------------------------------------------------------------------
- // TView::RemoveSubView:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewNonRes
-
- void TView::RemoveSubView(TView* theSubView)
- {
- DeleteSubView(theSubView);
-
- RemovedASubView(theSubView);
- theSubView->BeInSuperView(NULL);
- }
-
- //----------------------------------------------------------------------------------------
- // TView::Resize:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewNonRes
-
- void TView::Resize(const VPoint& newSize,
- Boolean invalidate)
- {
- SetFrame(VRect(fLocation, fLocation + newSize), invalidate);
- }
-
- //----------------------------------------------------------------------------------------
- // TView::RestrictRegionToVisible:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- void TView::RestrictRegionToVisible(RgnHandle aRegion)
- {
- #if qDebug
- AssumeFocused();
- #endif
-
- CRect itsVisibleExtent(ViewToQDRect(GetVisibleExtent()));
-
- CTemporaryRegion visibleExtentRgn;
-
- RectRgn(visibleExtentRgn, &itsVisibleExtent);
- SectRgn(aRegion, visibleExtentRgn, aRegion);
-
- // Intersect with visible region
- SectRgn(TWindow::GetVisRegion(qd.thePort), aRegion, aRegion);
- SectRgn(GetClipRegion(qd.thePort), aRegion, aRegion);
- }
-
- //----------------------------------------------------------------------------------------
- // TView::RevealBottom:
- //----------------------------------------------------------------------------------------
- #pragma segment MAScroll
-
- void TView::RevealBottom(Boolean redraw)
- {
- RevealRect(VRect(fSize, fSize), gZeroVPt, redraw);
- }
-
- //----------------------------------------------------------------------------------------
- // TView::RevealRect:
- //----------------------------------------------------------------------------------------
- #pragma segment MAScroll
-
- void TView::RevealRect(const VRect& rectToReveal,
- const VPoint& minToSee,
- Boolean redraw)
- {
- if (fSuperView)
- {
- VRect localRectToReveal(rectToReveal);
-
- LocalToSuperVRect(localRectToReveal);
- fSuperView->RevealRect(localRectToReveal, minToSee, redraw);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TView::RevealTop:
- //----------------------------------------------------------------------------------------
- #pragma segment MAScroll
-
- void TView::RevealTop(Boolean redraw)
- {
- RevealRect(gZeroVRect, gZeroVPt, redraw);
- }
-
- //----------------------------------------------------------------------------------------
- // TView::Show:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewNonRes
-
- void TView::Show(Boolean state,
- Boolean redraw)
- {
- if (state != fShown)
- {
- if (redraw)
- {
- fShown = TRUE; // So that ForceRedraw works.
- ForceRedraw();
- }
- InvalidateFocus();
- gDispatcher->InvalidateMouseRegions(); // Must re-calc cursor and help regions
- fShown = state;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TView::ShowReverted:
- //----------------------------------------------------------------------------------------
- #pragma segment MAReadFile
-
- void TView::ShowReverted()
- {
- AdjustFrame();
- ForceRedraw();
-
- if (HasSubViews())
- {
- CSubViewIterator iter(this);
-
- for (TView * theSubView = iter.FirstSubView(); iter.More(); theSubView = iter.NextSubView())
- theSubView->ShowReverted();
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TView::SubViewChangedFrame:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewNonRes
-
- void TView::SubViewChangedFrame(TView* /* theSubView */ ,
- const VRect& /* oldFrame */ ,
- const VRect& /* newFrame */ ,
- Boolean /* invalidate */)
- {
- // Just a warning. If you override this method to change your frame based on your
- // subview changing its frame you will need to be careful if your subviews have size
- // determiners of sizeRelSuperView. If you do, you will find yourself in an infinite
- // loop. For an sample solution look at TIncludeView::SubViewChangedFrame. Essentially
- // you have to be careful not to renotify your subviews that your frame has changed
- // since you are probably changing your frame because they changed theirs. I think you
- // get the picture.
- }
-
- //----------------------------------------------------------------------------------------
- // TView::SuperToLocal:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- void TView::SuperToLocal(VPoint& thePoint) const
- {
- thePoint -= GetLocalOffsetInSuper();
- }
-
- //----------------------------------------------------------------------------------------
- // TView::SuperToLocalVRect:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- void TView::SuperToLocalVRect(VRect& viewRect) const
- {
- viewRect -= GetLocalOffsetInSuper();
- }
-
- //----------------------------------------------------------------------------------------
- // TView::SuperToLocalRegion:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- void TView::SuperToLocalRegion(RgnHandle theRgn)
- {
- VPoint localViewPt(QDToViewPt(gZeroPt)); // get 0 in View Space
- LocalToSuper(localViewPt);
-
- CPoint superQDPt(fSuperView ? fSuperView->ViewToQDPt(localViewPt) : localViewPt.ToPoint());
-
- OffsetRgn(theRgn, (short) - superQDPt.h, (short) - superQDPt.v);
- }
-
- //----------------------------------------------------------------------------------------
- // TView::SuperViewChangedFrame:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewNonRes
-
- void TView::SuperViewChangedFrame(const VRect& oldFrame,
- const VRect& newFrame,
- Boolean invalidate)
- {
- if (oldFrame != newFrame)
- {
- VRect itsOldFrame(GetFrame());
- VRect itsNewFrame(itsOldFrame);
-
- for (VHSelect vhs = vSel; vhs <= hSel; ++vhs)
- switch (fSizeDeterminer[vhs])
- {
- case sizeRelSuperView:
- // need to capture the amount of change in the superview here for use
- // in ComputeFrame
- itsNewFrame[botRight][vhs] += newFrame.GetSize()[vhs] - oldFrame.GetSize()[vhs];
- break;
- }
-
- ComputeFrame(itsNewFrame);
- if (itsOldFrame != itsNewFrame)
- {
- SetFrame(itsNewFrame, invalidate);
- DoPagination();
- }
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TView::IsDoneTracking:
- //----------------------------------------------------------------------------------------
- #pragma segment MADoCommand
-
- Boolean TView::IsDoneTracking()
- {
- // Default to mouse-down tracking
- return !StillDown();
- }
-
- //----------------------------------------------------------------------------------------
- // TView::TrackConstrain:
- //----------------------------------------------------------------------------------------
- #pragma segment MADoCommand
-
- void TView::TrackConstrain(TrackPhase /* aTrackPhase */,
- const VPoint& /* anchorPoint */ ,
- const VPoint& /* previousPoint */ ,
- VPoint& /* nextPoint */ ,
- Boolean /* mouseDidMove */)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TView::TrackFeedback:
- //----------------------------------------------------------------------------------------
- #pragma segment MADoCommand
-
- void TView::TrackFeedback(TrackPhase /* aTrackPhase */,
- const VPoint& anchorPoint,
- const VPoint& /* previousPoint */ ,
- const VPoint& nextPoint,
- Boolean mouseDidMove,
- Boolean /* turnItOn */)
-
- // Use code like this to get a flickering rectangle.
- {
- if (mouseDidMove)
- {
- VRect vr(anchorPoint, nextPoint);
- vr.Validate();
-
- PenPat(&qd.gray);
- FrameRect(&ViewToQDRect(vr));
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TView::TrackMouse:
- //----------------------------------------------------------------------------------------
- #pragma segment MADoCommand
-
- void TView::TrackMouse(TrackPhase /* aTrackPhase */,
- VPoint& /* anchorPoint */ ,
- VPoint& /* previousPoint */ ,
- VPoint& /* nextPoint */ ,
- Boolean /* mouseDidMove */)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TView::Update:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- void TView::Update()
- {
- if (fSuperView)
- fSuperView->Update();
- else
- DrawContents();
- }
-
- //----------------------------------------------------------------------------------------
- // TView::GetValidationError:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- long TView::GetValidationError()
- {
- return noErr;
- }
-
- //----------------------------------------------------------------------------------------
- // TView::IsValid:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- Boolean TView::IsValid()
- {
- Boolean returnVal = TRUE;
-
- long result = GetValidationError();
- if (result != noErr)
- {
- ValidationFailed(result);
- returnVal = FALSE;
- }
-
- return returnVal;
- }
-
- //----------------------------------------------------------------------------------------
- // TView::ValidationFailed:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- void TView::ValidationFailed(long /* reason */)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TView::IsHierarchyValid:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- Boolean TView::IsHierarchyValid()
- {
- Boolean result = IsValid();
-
- if (result && HasSubViews())
- {
- CSubViewIterator iter(this);
-
- for (TView * theSubView = iter.FirstSubView(); iter.More(); theSubView = iter.NextSubView())
- {
- result = theSubView->IsHierarchyValid();
- if (!result)
- break;
- }
- }
-
- return result;
- }
-
- //----------------------------------------------------------------------------------------
- // TView::ValidateVRect:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- void TView::ValidateVRect(const VRect& goodVRect)
- {
- ValidateRect(ViewToQDRect(goodVRect));
- }
-
- //----------------------------------------------------------------------------------------
- // TView::ValidateRect:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- void TView::ValidateRect(const CRect& goodRect)
- {
- CTemporaryRegion goodRectRgn;
-
- RectRgn(goodRectRgn, &goodRect);
- ValidateRegion(goodRectRgn);
- }
-
- //----------------------------------------------------------------------------------------
- // TView::ValidateRegion:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- void TView::ValidateRegion(const RgnHandle goodRgn)
- {
- if (Focus())
- {
- CTemporaryRegion visibleGoodRgn;
-
- RectRgn(visibleGoodRgn, &ViewToQDRect(GetVisibleExtent()));
- SectRgn(goodRgn, visibleGoodRgn, visibleGoodRgn);
- if (!EmptyRgn(visibleGoodRgn))
- DoValidateRegion(visibleGoodRgn);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TView::DoValidateRegion:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- void TView::DoValidateRegion(const RgnHandle goodRgn)
- {
- if (fSuperView)
- fSuperView->DoValidateRegion(goodRgn); // see if someone knows how
- }
-
- //----------------------------------------------------------------------------------------
- // TView::ViewEnable:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- void TView::ViewEnable(Boolean state,
- Boolean redraw)
- {
- SetEnable(state);
-
- if (redraw)
- ForceRedraw();
- }
-
- //----------------------------------------------------------------------------------------
- // TView::ViewToQDPt:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- CPoint TView::ViewToQDPt(const VPoint& viewPt)
- {
- return (viewPt - GetViewToQDOffset()).ToPoint();
- }
-
- //----------------------------------------------------------------------------------------
- // TView::ViewToQDRect:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- CRect TView::ViewToQDRect(const VRect& viewRect)
- {
- return (viewRect - GetViewToQDOffset()).ToRect();
- }
-
- //----------------------------------------------------------------------------------------
- // TView::WindowToLocal:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- void TView::WindowToLocal(VPoint& thePoint) const
- {
- if (fSuperView)
- {
- fSuperView->WindowToLocal(thePoint);
- SuperToLocal(thePoint);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TView::AsPict:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewNonRes
-
- PicHandle TView::AsPict()
- {
- GrafPort tempPort;
- CGrafPort tempCPort;
-
- MAVolatileInit(GrafPtr, savedPort, GetGrafPort());
- MAVolatileInit(PicHandle, pHndl, NULL);
- MAVolatile(Boolean, pictureIsOpen);
-
- InvalidateFocus();
-
- gDrawingPictScrap = TRUE;
- gDrawingPictScrapView = this;
- if (qNeedsColorQD || HasColorQD())
- {
- OpenCPort(&tempCPort);
- BeInPort((GrafPort *) & tempCPort);
- SetPort((GrafPort *) & tempCPort);
- }
- else
- {
- OpenPort(&tempPort);
- BeInPort(&tempPort);
- SetPort(&tempPort);
- }
-
- FailInfo fi;
- Try(fi)
- {
- if (Focus())
- {
- //Open color or black && white, depending on the port
- CRect qdExtent(GetQDExtent());
- pHndl = OpenPicture(&qdExtent);
- pictureIsOpen = TRUE; // Failure handler needs to close it
- FailNIL(pHndl);
-
- ClipRect(&qdExtent);
- DrawContents();
- ClosePicture();
- pictureIsOpen = FALSE; // Failure handler doesn't need to close it
-
- // On the 128K ROMs the picFrame will be empty if drawing the
- // picture failed. On the 64K ROM's QuickDraw simply bombs.
- if (((CRect &)(*pHndl)->picFrame).Empty())
- {
- #if qDebug
- fprintf(stderr, "Picture frame is empty!\n");
- #endif
-
- FailOSErr(memFullErr);
- }
-
- InvalidateFocus();
- }
- #if qDebug
- else // can't focus
- ProgramBreak("Can't focus view while writing picture to desk scrap");
- #endif
-
- fi.Success();
- }
- else // Recover
- {
- if (pHndl)
- {
- if (pictureIsOpen)
- ClosePicture();
- pHndl = DisposeIfPicHandle(pHndl);
- }
-
- if (qNeedsColorQD || HasColorQD())
- CloseCPort(&tempCPort);
- else
- ClosePort(&tempPort);
- gDrawingPictScrap = FALSE;
- gDrawingPictScrapView = NULL;
- SetPort(savedPort);
- BeInPort(savedPort);
- fi.ReSignal();
- }
-
- if (qNeedsColorQD || HasColorQD())
- CloseCPort(&tempCPort);
- else
- ClosePort(&tempPort);
-
- gDrawingPictScrap = FALSE;
- gDrawingPictScrapView = NULL;
- SetPort(savedPort);
- BeInPort(savedPort);
-
- return pHndl;
- }
-
- //----------------------------------------------------------------------------------------
- // TView::WriteToDeskScrap:
- //----------------------------------------------------------------------------------------
- #pragma segment MAClipboard
-
- void TView::WriteToDeskScrap()
- {
- MAVolatileInit(PicHandle, pHndl, NULL);
-
- FailInfo fi;
- Try(fi)
- {
- pHndl = AsPict();
- FailNIL(pHndl);
-
- FailOSErr(gClipboardMgr->PutDeskScrapData('PICT', (Handle)pHndl));
-
- pHndl = DisposeIfPicHandle(pHndl); // dispose of picture created by AsPict
- // so failure handler doesn't to kill it
- fi.Success();
- }
- else // Recover
- {
- if (pHndl)
- {
- #if qDebug
- ProgramBreak("Failed to put PICT-type scrap");
- #endif
-
- pHndl = DisposeIfPicHandle(pHndl);
- }
- fi.ReSignal();
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TView::GoAwayByUser:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewNonRes
-
- void TView::GoAwayByUser(const VPoint& /* theMouse */ )
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TView::MoveByUser:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewNonRes
-
- void TView::MoveByUser(const VPoint& /* theMouse */ )
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TView::ResizeByUser:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewNonRes
-
- void TView::ResizeByUser(const VPoint& /* theMouse */ )
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TView::SetHLPenState:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewNonRes
-
- void TView::SetHLPenState(HLState fromHL,
- HLState toHL)
- {
- short mode = patXor; // every transition except hlOn <-> hlDim uses patXOR
-
- PatPtr pPat;
- if (fromHL + toHL == hlOffOn)
- pPat = &qd.black;
- else if (fromHL != toHL)
- pPat = &qd.gray;
-
- if (fromHL + toHL == hlDimOn)
- mode = notPatXor;
-
- PenMode(mode);
- PenPat(pPat);
- }
-
- //----------------------------------------------------------------------------------------
- // TView::UpdateCoordinates:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- void TView::UpdateCoordinates()
- {
- const short kMaxOriginFixup = 1024; // The maximum amount by which to _fixup_
- // (not offset) the QD origin when
- // focusing. This allows patterns and
- // pixpats to be pinned to global space as
- // they were intended. See note below.
- // Larger values than this may be required
- // for _extremely_ complex pixpats (not
- // patterns as they are restricted to 8
- // bit repetition.) The reason that the
- // fixup is restricted is that you don't
- // want to run off the end of QD space and
- // we already have slop allowance of about
- // 2k in ViewCoords.p.
-
- // we can't update our coordinates until our superview updates theirs
- // however once a views coordinates are valid we don't have to walk up
- // the tree any further.
- if (fCoordinatesAreInvalid)
- {
- if (fSuperView)
- fSuperView->UpdateCoordinates();
-
- CPoint oldQDOrigin(fQDOrigin);
- VPoint oldViewToQDOffset(fViewToQDOffset);
- VRect oldVisibleExtent(fVisibleExtent);
-
- if (fSuperView || (TPrintHandler::gCurrPrintHandler && (TPrintHandler::gCurrPrintHandler->fView == this)))
- {
- // First calculate and setup the new origins.
- // But first a word about this approach. (thanks Keith Rollins!) Problems with
- // pattern alignment when using 32bit views occur when virtual origin of the port
- // has coordinates that are not multiples of 8. This can occur if, for example,
- // you scroll a view by increments of other than 8, 16, or other multiple of 8.
- // The solution is to appropriately set the origin so that patterns are drawn
- // correctly aligned. This can be done by making sure that we set the origin to
- // some value that will cause QuickDraw to perform in exactly the same way as if
- // the origin were really at the value specified by fViewToQDOffset. Since classic
- // QuickDraw patterns repeat after 8 pixels, we can accomplish this task by making
- // sure that fViewToQDOffset is a multiple of 8, and setting the origin to
- // compensate by setting it to fViewToQDOffset % 8.
- // Unfortunately, this will only work for classic QuickDraw patterns that repeat
- // after 8 pixels. With PixPats, this period can be any power of 2. In order to
- // support them, we have to make sure that fViewToQDOffset must be only a multiple
- // of whatever power of 2 is being used. Ideally, therefore, we could like to make
- // the chunkiness of fViewToQDOffset to be as large as possible. On the other
- // hand, we can't make it too large, or else the amount by which we offset the
- // origin in TView.Focus may overflow QuickDraw's limits. Probably a value of 1024
- // or 2048 should be sufficient enough to accomodate the largest of PixPats a
- // developer may use, and still be small enough that we shouldn't overflow
- // QuickDraw.
- VPoint localOriginInSuper(GetLocalOffsetInSuper());
-
- VPoint actualViewToQDOffset;
- if (TPrintHandler::gCurrPrintHandler && (TPrintHandler::gCurrPrintHandler->fView == this))
- actualViewToQDOffset = TPrintHandler::gCurrPrintHandler->GetViewToQDOffset() + VPoint(TPrintHandler::gCurrPrintHandler->GetQDOrigin());
- else
- actualViewToQDOffset = fSuperView->fViewToQDOffset + VPoint(fSuperView->fQDOrigin) - localOriginInSuper;
-
- fViewToQDOffset = actualViewToQDOffset;// to allow testing of the Extent
- if (VRect(-kMaxCoord, -kMaxCoord, kMaxCoord, kMaxCoord).Contains(GetExtent()))
- {
- fQDOrigin = actualViewToQDOffset.ToPoint();
- fViewToQDOffset = gZeroVPt;
- }
- else
- {
- CPoint deltaOrigin = CPoint((short)(actualViewToQDOffset.h % kMaxOriginFixup), (short)(actualViewToQDOffset.v % kMaxOriginFixup));
- fViewToQDOffset = actualViewToQDOffset - VPoint(deltaOrigin);
- fQDOrigin = deltaOrigin;
- }
-
- // Update my visible extent by intersecting my extent with my superview's visible extent
-
- // When printing, or drawing the scrap, the grafPort is supplied.
- if ((gDrawingPictScrapView == this) || ((TPrintHandler::gCurrPrintHandler != NULL) && (TPrintHandler::gCurrPrintHandler->fView == this)))
- fVisibleExtent = GetExtent();
- else
- {
- VRect visibleExtent(GetFrame() & fSuperView->GetVisibleExtent());
- SuperToLocalVRect(visibleExtent);
- fVisibleExtent = visibleExtent;
- }
- }
- else
- {
- fViewToQDOffset = gZeroVPt;
- fQDOrigin = gZeroPt;
-
- fVisibleExtent = GetExtent();
- }
-
- fCoordinatesAreInvalid = FALSE;
- }
-
- }
-
- //----------------------------------------------------------------------------------------
- // TView::InvalidateCoordinates:
- //----------------------------------------------------------------------------------------
- void TView::InvalidateCoordinates()
- {
- if (!fCoordinatesAreInvalid)
- {
- fCoordinatesAreInvalid = TRUE;
-
- CSubViewIterator iter(this);
-
- for (TView * theSubView = iter.FirstSubView(); iter.More(); theSubView = iter.NextSubView())
- theSubView->InvalidateCoordinates();
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TView::GetVisibleExtent:
- //----------------------------------------------------------------------------------------
- VRect TView::GetVisibleExtent()
- {
- if (fCoordinatesAreInvalid)
- UpdateCoordinates();
-
- return fVisibleExtent;
- }
-
- //----------------------------------------------------------------------------------------
- // TView::GetQDOrigin:
- //----------------------------------------------------------------------------------------
- CPoint TView::GetQDOrigin()
- {
- if (fCoordinatesAreInvalid)
- UpdateCoordinates();
-
- return fQDOrigin;
- }
-
- //----------------------------------------------------------------------------------------
- // TView::GetViewToQDOffset:
- //----------------------------------------------------------------------------------------
- VPoint TView::GetViewToQDOffset()
- {
- if (fCoordinatesAreInvalid)
- UpdateCoordinates();
-
- return fViewToQDOffset;
- }
-
- //----------------------------------------------------------------------------------------
- // TView::ZoomByUser:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewNonRes
-
- void TView::ZoomByUser(const VPoint& /* theMouse */ ,
- short /* partCode */)
- {
- }
-
- //------------------------------------------------------------------------------------
- // Drag and Drop Methods
- //------------------------------------------------------------------------------------
-
- //----------------------------------------------------------------------------------------
- // TView::SetDroppable:
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- void TView::SetDroppable(Boolean
- #if qDrag
- isDroppable
- #endif
- )
- {
- #if qDrag
- if (HasDragManager())
- {
- TWindow * itsWindow = GetWindow();
- if (itsWindow != NULL)
- {
- if (isDroppable && !fDroppable)
- itsWindow->RegisterDroppableView(this);
- else if (!isDroppable && fDroppable)
- itsWindow->UnregisterDroppableView(this);
- }
- fDroppable = isDroppable;
- }
- #endif
- }
-
- #if qDrag
- //----------------------------------------------------------------------------------------
- // TView::HandleDragCursor:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- void TView::HandleDragCursor(const VPoint& theMouse,
- RgnHandle cursorRegion)
- {
- if (HasSubViews())
- {
- CSubViewIterator iter(this, kIterateBackward);
-
- for (TView * theSubView = iter.FirstSubView(); iter.More(); theSubView = iter.NextSubView())
- {
- VPoint subViewPt = theMouse;
-
- theSubView->SuperToLocal(subViewPt);
- if (theSubView->ContainsMouse(subViewPt) && (theSubView->DoGetDragProxy()->GetDraggable() || theSubView->HasSubViews()))
- {
- theSubView->HandleDragCursor(subViewPt, cursorRegion);
- // bring the cursor region back to our coordinate system
- theSubView->LocalToSuperRegion(cursorRegion);
- break;
- }
- }
- }
-
- if (EmptyRgn(cursorRegion) && Focus())
- {
- GetExtentRegion(cursorRegion);
-
- if (HasSubViews())
- {
- CTemporaryRegion subViewFrameRgn;
- CSubViewIterator iter(this);
-
- for (TView * theSubView = iter.FirstSubView(); iter.More(); theSubView = iter.NextSubView())
- {
- if (theSubView->DoGetDragProxy()->GetDraggable() || theSubView->HasSubViews())
- {
- theSubView->GetExtentRegion(subViewFrameRgn);
- theSubView->LocalToSuperRegion(subViewFrameRgn);
- DiffRgn(cursorRegion, subViewFrameRgn, cursorRegion);
- }
- }
- }
-
- RgnHandle dragCursorRegion = NULL;
- if (!DoSetDragCursor(theMouse, cursorRegion, dragCursorRegion))
- {
- if (dragCursorRegion)
- DiffRgn(cursorRegion, dragCursorRegion, cursorRegion);
- SetCursor(&(qd.arrow));
- }
-
- DisposeIfRgnHandle(dragCursorRegion);
-
- RestrictRegionToVisible(cursorRegion);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TView::DoSetDragCursor:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- Boolean TView::DoSetDragCursor(const VPoint& localPoint,
- RgnHandle cursorRegion,
- RgnHandle& dragCursorRegion)
- {
- #if qDebug
- Assertion(dragCursorRegion == NULL, "\pdragCursorRegion should be NULL");
- AssumeFocused();
- #endif
-
- dragCursorRegion = DoMakeDragCursorRegion();
- Boolean usingDragCursor = WillDrag(localPoint, dragCursorRegion);
- if (usingDragCursor)
- {
- // cursor region is the intersection of the drag region
- // and the provided cursor region
- FailNIL(dragCursorRegion);
- SectRgn(cursorRegion, dragCursorRegion, cursorRegion);
- short cursorID = GetWillDragCursorID();
- if (cursorID != kNoResource)
- {
- CursHandle aCursor = GetCursor(cursorID);
- FailNILResource((Handle)aCursor);
- SetCursor(*aCursor);
- }
- else
- SetCursor(&(qd.arrow));
- }
-
- return usingDragCursor;
- }
-
- //----------------------------------------------------------------------------------------
- // TView::GetWillDragCursorID:
- //----------------------------------------------------------------------------------------
- #pragma segment MADragRes
-
- short TView::GetWillDragCursorID()
- {
- return kOpenHandCursor;
- }
-
- //----------------------------------------------------------------------------------------
- // TView::GetIsDraggingCursorID:
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- short TView::GetIsDraggingCursorID()
- {
- return kClosedHandCursor;
- }
-
- //----------------------------------------------------------------------------------------
- // TView::DoMakeDragCursorRegion:
- //----------------------------------------------------------------------------------------
- #pragma segment MADragRes
-
- RgnHandle TView::DoMakeDragCursorRegion()
- {
- RgnHandle dragCursorRegion = NULL;
-
- if (GetDraggable())
- dragCursorRegion = DoMakeDropHiliteRegion();// simple case
-
- return dragCursorRegion;
- }
-
- //----------------------------------------------------------------------------------------
- // TView::WillDrag
- //----------------------------------------------------------------------------------------
- #pragma segment MADragRes
-
- Boolean TView::WillDrag(const VPoint& localMouse,
- const RgnHandle dragCursorRegion)
- {
- return dragCursorRegion && GetDraggable() ? PtInRgn(ViewToQDPt(localMouse), dragCursorRegion) : FALSE;
- }
-
- //----------------------------------------------------------------------------------------
- // TView::DoGetDragProxy:
- //----------------------------------------------------------------------------------------
- #pragma segment MADragRes
-
- TView* TView::DoGetDragProxy()
- {
- return this; // default is to not provide a proxy
- }
-
- //----------------------------------------------------------------------------------------
- // TView::HandleDrag:
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- void TView::HandleDrag(TToolboxEvent* event)
- {
- MAVolatileInit(RgnHandle, dragRegion, NULL);
-
- FailInfo fi;
- Try(fi)
- {
- TDragDropSession::fgDragDropSession->ClearDrag();
- DoAddDragContent();
- dragRegion = DoMakeDragOutlineRegion();
- TDragDropSession::fgDragDropSession->StartDrag(this, event, dragRegion);
- fi.Success();
- }
- else // Recover
- {
- DisposeIfRgnHandle(dragRegion);
- fi.ReSignal();
- }
-
- DisposeIfRgnHandle(dragRegion);
- }
-
- //----------------------------------------------------------------------------------------
- // TView::DoAddDragContent:
- //----------------------------------------------------------------------------------------
- #pragma segment MANever
-
- void TView::DoAddDragContent()
- {
- SubClassResponsibility();
- }
-
- //----------------------------------------------------------------------------------------
- // TView::DoMakeDragOutlineRegion
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- RgnHandle TView::DoMakeDragOutlineRegion()
- {
- // The drag outline region will usually match the drag cursor region.
- RgnHandle dragOutlineRegion = DoMakeDragCursorRegion();
- CTemporaryRegion tempRegion;
-
- CopyRgn(dragOutlineRegion, tempRegion); // make it an outline
- InsetRgn(tempRegion, 1, 1);
- DiffRgn(dragOutlineRegion, tempRegion, dragOutlineRegion);
-
- LocalToGlobalRegion(dragOutlineRegion); // globalize
-
- return dragOutlineRegion;
- }
-
- //----------------------------------------------------------------------------------------
- // TView::WillAcceptDrop:
- //----------------------------------------------------------------------------------------
- #pragma segment MANever
-
- Boolean TView::WillAcceptDrop(CDragItemIterator&/* dragItemIterator */ )
- {
- SubClassResponsibility();
-
- return FALSE;
- }
-
- //----------------------------------------------------------------------------------------
- // TView::DoDragEnter:
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- void TView::DoDragEnter()
- {
- // set up private data used to track drag
- }
-
- //----------------------------------------------------------------------------------------
- // TView::DoMakeDropHiliteRegion:
- //----------------------------------------------------------------------------------------
- #pragma segment MADragRes
-
- RgnHandle TView::DoMakeDropHiliteRegion()
- {
- RgnHandle dropRegion = MakeNewRgn();
- RectRgn(dropRegion, &ViewToQDRect(GetVisibleExtent()));
-
- return dropRegion;
- }
-
- //----------------------------------------------------------------------------------------
- // TView::DragWithin:
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- void TView::DoDragWithin(const VPoint& /*localMouse*/ )
- {
- // update tracking data and visuals
- }
-
- //----------------------------------------------------------------------------------------
- // TView::DoDragLeave:
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- void TView::DoDragLeave()
- {
- // clean up after the drag has left
- }
-
- //----------------------------------------------------------------------------------------
- // TView::DoMakeDropLocationDescriptor:
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- Boolean TView::DoMakeDropLocationDescriptor(CAEDesc& dropLocationDesc)
- {
- // Default implementation is to return a description of the containing window.
- // Subclasses of TView that mix MScriptable object may choose to describe themselves rather
- // than their containing window.
- Boolean result = FALSE;
- TWindow * myWindow = GetWindow();
-
- if (myWindow)
- {
- FailInfo fi;
- Try(fi)
- {
- result = myWindow->MakeObjectSpecifier(dropLocationDesc, formAbsolutePosition);
- fi.Success();
- }
- // no resignal on failure
- }
- return result;
- }
-
- //----------------------------------------------------------------------------------------
- // TView::WillDragMove:
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- Boolean TView::WillDragMove(TView* destinationView)
- {
- Boolean isMove;
-
- // test the family id's first
- isMove = (GetDragMoveFamily() == destinationView->GetDragMoveFamily());
-
- if (isMove)
- {
- switch (GetDragMoveDeterminer())
- {
- case kNeverMove:
- isMove = FALSE;
- break;
-
- case kMoveWithinView:
- isMove = (this == destinationView);
- break;
-
- case kMoveWithinWindow:
- isMove = (GetWindow() == destinationView->GetWindow());
- break;
-
- case kMoveWithinContext:
- isMove = (GetContext(cDragMove) == destinationView->GetContext(cDragMove));
- break;
-
- case kMoveWithinApplication: // already true.
- break;
-
- default:
- isMove = FALSE; // unknown context value
- break;
- }
- }
-
- return isMove;
- }
-
- //----------------------------------------------------------------------------------------
- // TView::DoMakeDragDropCommand:
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- TCommand* TView::DoMakeDragDropCommand(CommandNumber/* itsCommandNumber */ ,
- CDragItemIterator&/* dragItemIterator */ )
- {
- return NULL; // subview responsibility
- }
-
- //----------------------------------------------------------------------------------------
- // TView::DoFulfillPromise:
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- void TView::DoFulfillPromise(TDragItem* /*promisedItem */ )
- {
- // subview responsibility
- }
-
- #endif // qDrag
-
- //========================================================================================
- // CLASS TIncludeView
- //========================================================================================
- #undef Inherited
- #define Inherited TView
-
- #pragma segment MAOpen
- MA_DEFINE_CLASS_M1(TIncludeView,
- Inherited);
-
- //----------------------------------------------------------------------------------------
- // TIncludeView constructor.
- //----------------------------------------------------------------------------------------
- #pragma segment MAOpen
-
- TIncludeView::TIncludeView() :
- fIncludeRsrcID(kNoResource),
- fItsSubViewOffset(gZeroVPt),
- fResourceAttributes(resPurgeable)
- {
- fEnabled = FALSE;
- }
-
- //----------------------------------------------------------------------------------------
- // TIncludeView destructor
- //----------------------------------------------------------------------------------------
- #pragma segment MADestructorRes
-
- TIncludeView::~TIncludeView()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TIncludeView::IIncludeView:
- //----------------------------------------------------------------------------------------
- #pragma segment MAOpen
-
- void TIncludeView::IIncludeView(TDocument* itsDocument,
- TView* itsSuperView,
- short includeRsrcID,
- const VPoint& itsSubViewOffset,
- const CStr255& resourceName,
- short resourceAttributes)// override
- {
- IView(itsDocument, itsSuperView, gZeroVPt, itsSuperView->fSize, sizeSuperView, sizeSuperView);
-
- fIncludeRsrcID = includeRsrcID;
- fItsSubViewOffset = itsSubViewOffset;
- fResourceName = resourceName;
- fResourceAttributes = resourceAttributes;
- }
-
- //----------------------------------------------------------------------------------------
- // TIncludeView::GetStandardSignature:
- //----------------------------------------------------------------------------------------
- #pragma segment MAWriteResource
-
- IDType TIncludeView::GetStandardSignature() // override
- {
- return kStdIncludeAt;
- }
-
- //----------------------------------------------------------------------------------------
- // TIncludeView::DoPostCreate:
- //----------------------------------------------------------------------------------------
- #pragma segment MAOpen
-
- void TIncludeView::DoPostCreate(TDocument* itsDocument)// override
- {
- Inherited::DoPostCreate(itsDocument);
-
- TView * aView = NULL;
-
- // It only makes sense to do this stuff if we have a view to include.
- if (fIncludeRsrcID != kNoResource)
- {
- if (fSuperView)
- {
- // initially, make me "look like" my superview
- Locate(gZeroVPt, kDontInvalidate);
- Resize(fSuperView->fSize, kDontInvalidate);
- }
-
- // get the 'View' resource
- Handle viewResource = GetResource('View', fIncludeRsrcID);
- #if qDebug
- if (!viewResource)
- {
- viewResource = GetResource('view', fIncludeRsrcID);
- if (viewResource)
- {
- ProgramBreak("Use ViewPromoter. Program contains 2.0 'view' resources");
- ReleaseResource(viewResource);
- viewResource = NULL;
- }
- }
- #endif
-
- FailNILResource(viewResource);
-
- short theID;
- ResType theType;
- GetResInfo(viewResource, &theID, &theType, fResourceName);
-
- fResourceAttributes = GetResAttrs(viewResource);
-
- // create the included view
- aView = gViewServer->DoCreateViews(fDocument, this, fIncludeRsrcID, gZeroVPt);
- FailNIL(aView);
-
- // now, make me "look like" my subview
- fSizeDeterminer[vSel] = aView->fSizeDeterminer[vSel];
- fSizeDeterminer[hSel] = aView->fSizeDeterminer[hSel];
- SubViewChangedFrame(aView, gZeroVRect, VRect(fItsSubViewOffset, fItsSubViewOffset + aView->fSize), kDontInvalidate);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TIncludeView::ReadFields:
- //----------------------------------------------------------------------------------------
- #pragma segment MAReadResource
-
- void TIncludeView::ReadFields(TStream* aStream)
- {
- Inherited::ReadFields(aStream);
-
- VPoint itsSubViewOffset;
- FailInfo fi;
- Try(fi)
- {
- fIncludeRsrcID = aStream->ReadInteger();
-
- aStream->ReadVPoint(itsSubViewOffset);
- fItsSubViewOffset = itsSubViewOffset;
- fi.Success();
- }
- else // Recover
- {
- Free();
- fi.ReSignal();
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TIncludeView::WriteFields:
- //----------------------------------------------------------------------------------------
- #pragma segment MAWriteResource
-
- void TIncludeView::WriteFields(TStream* aStream)
- {
- Inherited::WriteFields(aStream);
-
- aStream->WriteInteger(fIncludeRsrcID);
-
- VPoint itsSubViewOffset = fItsSubViewOffset;
- aStream->WriteVPoint(itsSubViewOffset);
- }
-
- //----------------------------------------------------------------------------------------
- // TIncludeView::WriteSubViews:
- //----------------------------------------------------------------------------------------
- #pragma segment MAWriteResource
-
- void TIncludeView::WriteSubViews(TStream* aStream)
- {
- // our subviews are "included" and therefore not writeable, so don't call Inherited
- aStream->WriteInteger(0); // write out count of 0 subviews
-
- // Call into ViewServer to write out my subview to a 'View' resource with id=fIncludeRsrcID.
- #if qDebugMsg
- if (CountSubViews() != 1)
- fprintf(stderr, "TIncludeView::WriteTo only support writing of the first subview.\n");
- #endif
-
- if (fIncludeRsrcID != kNoResource)
- {
- CStr255 name = fResourceName;
- gViewServer->WriteViewsToResource(FirstSubView(), fIncludeRsrcID, name, fResourceAttributes);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TIncludeView::SubViewChangedFrame:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewNonRes
-
- void TIncludeView::SubViewChangedFrame(TView* ,
- const VRect& ,
- const VRect& newFrame,
- Boolean invalidate)
- {
- // Assume that TIncludeView has only 1 subview and that this view should remain the
- // same size as this one subview. We need to duplicate most of SetFrame here except
- // that we don't want to renotify our subviews that our frame has changed, especially
- // if our subview has size determiners of sizeRelSuperView.
-
- VRect oldFrame(GetFrame());
-
- VRect computedFrame(newFrame);
- computedFrame += fLocation; // offset newFrame by my location
-
- if (computedFrame != oldFrame)
- {
-
- // update the frame stored in the view
- fLocation = computedFrame[topLeft];
- fSize = computedFrame.GetSize();
-
- InvalidateFocus(); // Must re-focus because frame changed
- InvalidateCoordinates(); // Re-calc all the offsets
- gDispatcher->InvalidateMouseRegions(); // Must re-calc cursor and help regions
-
- if (invalidate)
- InvalidateFrameDifference(oldFrame, computedFrame);
-
- // • Let my adorners know that my frame changed
- NotifyAdornersOfFrameChange(oldFrame, computedFrame, invalidate);
-
- // • Let my superview know that my frame changed
- if (fSuperView)
- fSuperView->SubViewChangedFrame(this, oldFrame, computedFrame, invalidate);
- }
- }
-
- //========================================================================================
- // static functions
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // VisibleRect:
- //----------------------------------------------------------------------------------------
- #pragma segment MAGlobalsRes
-
- void TView::VisibleRect(CRect& rectToRestrict)
- {
- CTemporaryRegion rRgn;
-
- RectRgn(rRgn, &rectToRestrict);
- VisibleRgn(rRgn);
-
- rectToRestrict = (*(RgnHandle)rRgn)->rgnBBox;
- }
-
- //----------------------------------------------------------------------------------------
- // DrawableRect:
- //----------------------------------------------------------------------------------------
- #pragma segment MAGlobalsRes
-
- void TView::DrawableRect(CRect& rectToRestrict)
- {
- VisibleRect(rectToRestrict);
-
- CTemporaryRegion rRgn;
-
- RectRgn(rRgn, &rectToRestrict);
- DrawableRgn(rRgn);
-
- rectToRestrict = (*(RgnHandle)rRgn)->rgnBBox;
- }
-
- //----------------------------------------------------------------------------------------
- // VisibleRgn:
- //----------------------------------------------------------------------------------------
- #pragma segment MAGlobalsRes
-
- void TView::VisibleRgn(RgnHandle rgn)
- {
- if (!gPrinting && !gDrawingPictScrap)
- SectRgn(rgn, TWindow::GetVisRegion(qd.thePort), rgn);
- }
-
- //----------------------------------------------------------------------------------------
- // DrawableRgn:
- //----------------------------------------------------------------------------------------
- #pragma segment MAGlobalsRes
-
- void TView::DrawableRgn(RgnHandle rgn)
- {
- SectRgn(rgn, GetClipRegion(qd.thePort), rgn);
- }
-
- //----------------------------------------------------------------------------------------
- // PtAndRgn:
- //----------------------------------------------------------------------------------------
- #pragma segment MAGlobalsRes
-
- void TView::PtAndRgn(CPoint aPoint,
- RgnHandle aRegion)
- {
- CTemporaryRegion aPointRgn;
-
- SetRectRgn(aPointRgn, aPoint.h, aPoint.v, aPoint.h + 1, aPoint.v + 1);
- UnionRgn(aPointRgn, aRegion, aRegion);
- }
-
- //----------------------------------------------------------------------------------------
- // VRectAndRgn:
- //----------------------------------------------------------------------------------------
- #pragma segment MAGlobalsRes
-
- void TView::VRectAndRgn(const VRect& theVRect,
- RgnHandle theRgn)
- {
- CTemporaryRegion theVRectRgn;
-
- RectRgn(theVRectRgn, &theVRect.ToRect());
- UnionRgn(theVRectRgn, theRgn, theRgn);
- }
-
- //----------------------------------------------------------------------------------------
- // IsPtVisible:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- Boolean TView::IsPtVisible(CPoint pt)
- {
- return PtInRgn(pt, TWindow::GetVisRegion(qd.thePort));
- }
-
- //----------------------------------------------------------------------------------------
- // IsPtDrawable:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- Boolean TView::IsPtDrawable(CPoint pt)
- {
- return IsPtVisible(pt) && PtInRgn(pt, GetClipRegion(qd.thePort));
- }
-
- //----------------------------------------------------------------------------------------
- // IsRectVisible:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- Boolean TView::IsRectVisible(const CRect& r)
- {
- return RectInRgn(&r, TWindow::GetVisRegion(qd.thePort));
- }
-
- //----------------------------------------------------------------------------------------
- // IsRectDrawable:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- Boolean TView::IsRectDrawable(const CRect& r)
- {
- return IsRectVisible(r) && RectInRgn(&r, GetClipRegion(qd.thePort));
- }
-
- //----------------------------------------------------------------------------------------
- // GetFocus:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- void TView::GetFocus(FocusRec& theFocusRec)
- {
- GetViewPortInfo(theFocusRec.itsViewPortInfo);
-
- theFocusRec.focusedView = gFocusedView;
- theFocusRec.printing = gPrinting;
- theFocusRec.drawingPictScrap = gDrawingPictScrap;
- theFocusRec.drawingPictScrapView = gDrawingPictScrapView;
- }
-
- //----------------------------------------------------------------------------------------
- // SetFocus:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- void TView::SetFocus(const FocusRec& theFocusRec)
- {
- gFocusedView = theFocusRec.focusedView;
- gPrinting = theFocusRec.printing;
- gDrawingPictScrap = theFocusRec.drawingPictScrap;
- gDrawingPictScrapView = theFocusRec.drawingPictScrapView;
-
- SetViewPortInfo(theFocusRec.itsViewPortInfo);
- }
-
- //----------------------------------------------------------------------------------------
- // GetViewPortInfo:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- void TView::GetViewPortInfo(ViewPortInfo& theViewPortInfo)
- {
- GetPort(&(theViewPortInfo.port));
- GetClip(theViewPortInfo.clip);
- theViewPortInfo.org = ((CRect &)theViewPortInfo.port->portRect)[topLeft];
- theViewPortInfo.isValid = TRUE;
- }
-
- //----------------------------------------------------------------------------------------
- // SetViewPortInfo:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- void TView::SetViewPortInfo(const ViewPortInfo& theViewPortInfo)
- {
- if (qd.thePort != theViewPortInfo.port) // be nice to accelerator cards
- SetPort(theViewPortInfo.port);
- if (((CRect &)qd.thePort->portRect)[topLeft] != theViewPortInfo.org)
- SetOrigin(theViewPortInfo.org.h, theViewPortInfo.org.v);
- SetClip(theViewPortInfo.clip);
- }
-
- //----------------------------------------------------------------------------------------
- // WriteFocus:
- //----------------------------------------------------------------------------------------
- #if qDebug
- #pragma segment MADebug
-
- void TView::WriteFocus()
- {
- fprintf(stderr, " fViewToQDOffset = %s\n", (const char*)gFocusedView->fViewToQDOffset);
- fprintf(stderr, " portRect = %s\n", (const char*)((CRect &)qd.thePort->portRect));
- fprintf(stderr, " visRgn = %s\n", (const char*)((CRect &)(*TWindow::GetVisRegion(qd.thePort))->rgnBBox));
- fprintf(stderr, " clipRgn = %s\n", (const char*)((CRect &)(*GetClipRegion(qd.thePort))->rgnBBox));
- }
- #endif
-
- //----------------------------------------------------------------------------------------
- // GetClipRegion:
- //----------------------------------------------------------------------------------------
- #pragma segment MAWindowRes
-
- RgnHandle TView::GetClipRegion(GrafPtr theGrafPtr)
- {
- return theGrafPtr->clipRgn;
- }
-
-
- //----------------------------------------------------------------------------------------
- // TView::InitUView
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- void TView::InitUView(Boolean
- #if qGXViews || qGXPrinting
- initGX
- #endif
- )
- {
- #if qGXViews || qGXPrinting
- if (initGX && HasQDGXGraphics())
- {
- static const long kGXUsegaszRsrc = 0; // '0' indicates that GX should use the 'gasz' rsrc in your app
-
- gGXGraphicsClient = GXNewGraphicsClient(nil, kGXUsegaszRsrc, 0);
-
- if (gGXGraphicsClient)
- GXEnterGraphics();
- }
- #endif
-
- }
-
- //----------------------------------------------------------------------------------------
- // TView::TerminateUView
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- void TView::TerminateUView()
- {
- #if qGXViews || qGXPrinting
- if (gGXGraphicsClient)
- {
-
- GXDisposeGraphicsClient(gGXGraphicsClient);
- gGXGraphicsClient = NULL;
-
- // Only need checking if debugging the application
- GXExitGraphics();
- }
- #endif
-
- }
-
- //----------------------------------------------------------------------------------------
- // End of UView.cp
-
- #pragma segment Inline
-
-